Search code examples
javascriptjquerygoogle-analyticsumbraco7

Analytics event code shows up in source code but not in console


I have a problem on an Umbraco website and it completely baffles me. For Analytics I have added a event code on several download buttons. On most of the buttons it works perfectly, but there is one that is giving me a headache.

When I look at the source code (in Firefox, Chrome and Edge) the code show up fine:

<a onClick="ga('send', 'event', { eventCategory: 'Downloads', eventAction: 'Download document', eventLabel: 'Download document'});" href="/media/181927/06_product-overview_en_v07-2017_web.pdf" class="styledbutton css3trans" rel="external">Download</a>

But the click does not register and when I inspect the element with F12 it looks like this:

<a onclick="this.target='_blank'" href="/media/181927/06_product-overview_en_v07-2017_web.pdf" class="styledbutton css3trans" rel="external" title="Deze link opent in een nieuw venster">Download</a>

Does anybody have a clue how this can happen?


Solution

  • Alright, I found the problem. There was indeed a bit of code in my site's global.js file that overwrote my tracking code.

    I found it by searching my entire Visual Studio solution with ctlr-shift-f for a line that said: "this.target='_blank'"

    After commenting that part out of the global.js file my tracking code works like it should.

    Tnx Eike Pierstorff for pointing me in the right direction