MOPUB, custom MRAID event


#1

I’m trying to connect JS event with MOPUB SDK. Below is my JS basic structure. I tell mraid to listen to cutomeEvent. How do i trigger this event from iOS using MoPub SDK? Any help would be appreciated.

function myMraidIsReady(){
	
	alert("MRAID Ready inside");
	
	mraid.addEventListener('error', handleErrorEvent);
        mraid.addEventListener('stateChange', handleStateChangeEvent);
        mraid.addEventListener('customEvent', customEvent);
    
	prwin.prAddEvent('pi',(function(z){
		if (z == prwin.PRPID || z == PRPID){
			mraid.expand();
		}
 	}
))};

    function customEvent(something){
    	alert("custom event");
    }

#2

Hey there!

The MoPub SDK supports the standard MRAID events like ‘ready’ and ‘stateChange’ as they are defined in the IAB MRAID 1.0 specification
Anything beyond the MRAID 1.0 specification must be added to the SDK on your own.

Standard disclaimer applies here… if you want to modify the MoPub SDK to broadcast your own “custom MRAID event”, you can certainly do so, but beware, proceed at your own risk. :slight_smile:

Cautionary language aside: in order to do this, what you can do is modify the off-the-shelf mraid.js implementations in your SDK (links below) so that they ‘broadcast’ their own custom MRAID event based on another event that I assume you are also defining yourself.
If you do that successfully, the ‘customEvent’ eventListener that you provided above should trigger and then call your customEvent function.

The MoPub SDK mraid implementations can be found here:
iOS mraid.js
Android mraid.js