Skip to content

Instantly share code, notes, and snippets.

@spra85
Created January 30, 2017 20:31
Show Gist options
  • Save spra85/2b2192069040b6651189a5fc2c3e593b to your computer and use it in GitHub Desktop.
Save spra85/2b2192069040b6651189a5fc2c3e593b to your computer and use it in GitHub Desktop.

Amazon Notes

All of this work should be isolated to the bulbs-public-ads-manager.

This custom criteria key they use is amznslots. We do use async mode, e.g. amznads.setTargetingForGPTAsync

Step 1

<script type='text/javascript'>
    var amznads = amznads || {};
    var googletag = googletag || {};
    googletag.cmd = googletag.cmd || [];
    amznads.asyncParams = {
        'id': '3076',
        'callbackFn': function() {
            try {
                amznads.setTargetingForGPTAsync('amznslots');
            } catch (e) { /*ignore*/ }
       /* Continue your DFP call here (optional) */
        },
        'timeout': 2e3
    };
    (function() {
        var a, s = document.getElementsByTagName("script")[0];
        a = document.createElement("script");
        a.type = "text/javascript";
        a.async = true;
        a.src = "http://c.amazon-adsystem.com/aax2/amzn_ads.js";
        s.parentNode.insertBefore(a, s);
    })();
</script>

When ad library is initialized, call:

1. amznads.getAds('3076'); // in `initGoogleTag` logic
2. amznads.setTargetingForGPTAsync('amznslots'); // in `setSlotTargeting` method

Need to use this call back with changes to refreshSlot

amznads.getAdsCallback(id, callbackFunction, timeout, size) 

Should remember to clear:

googletag.pubads().clearTargeting('amznslots'); // clear custom targeting value by key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment