0
votes

I am trying to track views and clicks for advertisements on my web page. I am using google admanager to serve them and trying to use google analytics to track them via events.

My code runs perfectly if I run it outside of google admanager. Events are sent and logged. If I serve the same code up via admanager, everything works but a network call is never made to analytics. Are they blocking it so that you have to be on 360?

Here is my code. Perhaps I am just doing something incorrectly?

My code: Set up GA

<script laguauge="javascipt"> (function(i,s,o,g,r,a,m) {i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

Create the function to send the event:

function trackAdLink() {
  return function(){
    url = document.getElementById("amznBanners_assoc_banner_placement_default_0_a").href;
    event.preventDefault();

    ga('create', 'UA------4', 'auto');

    setTimeout(opLink(url), 1000);
    var openedLink = false;

    function opLink(url) {
      if (!openedLink) {
        openedLink = true;
        window.open(url, '_blank');
      }
    }


    ga('send', {
      hitType: 'event',
      eventCategory: 'Advertisement',
      eventAction: 'amazon',
      eventLabel: 'banner',
      'hitCallback': opLink(url)
    })
  };
};

Set up the advertisement url and create an onclick event

window.onload = function(e){
  var amazondiv = document.getElementById("amzndiv");
  var gadmlnk = document.getElementById("gadm");
  var amznlnk = document.getElementById("amznBanners_assoc_banner_placement_default_0_a");
  var amzncb = Math.floor((Math.random() * 1000000) + 1);
  var gcblnk = "&amzncb=" + amzncb;

  document.getElementById("amznBanners_assoc_banner_placement_default_0_a").href = gadmlnk.href + amznlnk.href + gcblnk;
  amzndiv.addEventListener("click", trackAdLink()); 
}
</script>
<div id="amazondiv">
     <a id="gadm" href="http://adclick.g.doubleclick.net/pcs/click-----"></a>

`

Advertiser's code:

<div id="amznBanners_assoc_banner_placement_default_0_div">
        <img id="amznBanners_assoc_banner_placement_default_0_img" usemap="#amznBanners_assoc_banner_placement_default_0_boxmap" src="https://images-na.ssl-images-amazon.com/images/G/01/warehouse-deals/Associates/General/wd-med-rectangle-products._V379029663_.png">
            <map name="amznBanners_assoc_banner_placement_default_0_boxmap">
                <area id="amznBanners_assoc_banner_placement_default_0_privacybox" shape="rect" coords="(0,238,300,250)" href="http://rcm-na.amazon-adsystem.com/e/cm/privacy-policy.html?o=1" target="_top" rel="nofollow">
                <area id="amznBanners_assoc_banner_placement_default_0_a" shape="rect" coords="0,0,10000,10000" href="https://aax-us-east.amazon-adsystem.com/x/c/---/https://www.amazon.com/b/ref=as_acph_wh_mainb_722_on?ref-refURL=https%3A%2F%2Fadmanager.google.com&amp;slotNum=0&amp;imprToken=-----&amp;tag=--20&amp;linkCode=w20&amp;node=10158976011&amp;amzncb=37221" target="_top" rel="nofollow">
            </map>
</div>

As you can see, I was trying to make sure that the event would be sent by creating callbacks and timeouts, per DFP documentation. Personal information has been removed.

1
Thank you for this tool. - lost.in.userspace
This code is running in an iframe, make sure you load any third party libraries you need in that frame. - BeWarned

1 Answers

1
votes

The answer is no. Google DFP does not block events sent to analytics.