Using the Google Ad Mob Javascript API (google_mobile_app_ads.js)

535 views
Skip to first unread message

Brian Fallon

unread,
Oct 23, 2013, 10:41:25 AM10/23/13
to google-adm...@googlegroups.com
Hi,

I using the media.admob.com/api/v1/google_mobile_app_ads.js within DFP to send events back to the app. I'm just wondering if this file is automatically cached by the SDK or is it loaded via http. The reason that I'm asking is that I've extracted out only the part I need which is for app events and I'm wondering if its more efficient to simply include this snippet into the ad itself rather than loading the entire script over HTTP. Any help is much appreciated.

Here is the snippet anyway, it uses Iframes and the GMSG protocol to send the info to the app. 


dfpAppEvent = {
    
    dispatch: function(a,b) {
        var c = {"name":a, "info":b, "google.afma.Notify_dt":(new Date).getTime()},
            d = ["gmsg://mobileads.google.com/appEvent"],
            e, u;
        for (e in c) d.push("&", a, "" === c[e] ? "" : "=", encodeURIComponent(String(c[e])));
        d[1] && (c = d[0], e = c.indexOf("#"), 0 <= e && (d.push(c.substr(e)), d[0] = c = c.substr(0, e)), e = c.indexOf("?"), 0 > e ? d[1] = "?" : e == c.length - 1 && (d[1] = void 0));
        u = d.join("");
    
        if("loading" == document.readyState)
        {            
            document.write("<iframe style=\"display:none\" src="+u+"></iframe>");
        }
        else
        {
            var e = document.body;
            var a;
            a = document.createElement("IFRAME");
            a.id = "afma-notify-" + (new Date).getTime();
            a.style.display = "none";
            a.src = u;
            e.appendChild(a)        
        }
    }
};
 
dfpAppEvent.dispatch("event_name", "event_value");
 

Eric Leichtenschlag

unread,
Oct 24, 2013, 6:18:19 PM10/24/13
to google-adm...@googlegroups.com
Hi Brian,

While this may be slightly more efficient, but if the SDK ever changes the way it responds to this protocol, or if the script fixes a bug in this method, your ad won't get that fix. I would highly recommend sacrificing the small data gain just including the script and using admob.events.dispatchAppEvent(name, value) to ensure that the ad won't break and cause you future headaches.

Thanks,
Eric
Reply all
Reply to author
Forward
0 new messages