AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
2K members online now
2K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Adding GA event tracking code to javascript

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi, I am attempting to add this GA event tracking code:

onclick="__gaTracker('send', 'event', 'Advertisement', 'http://www.penguin.com/book/its-never-too-late-to-begin-again-by-julia-cameron-with-emma-lively/9780... 'Tarcher Cameron Book');"

 

to this Javacript code which is in itself a banner with it's own tracking code of a third-party developer. My intention is to track clicks on the external URL.

 

<SCRIPT language='JavaScript1.1' src="https://ad.doubleclick.net/ddm/adj/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[t...
</SCRIPT>
<NOSCRIPT>
<A HREF="https://ad.doubleclick.net/ddm/jump/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[...
<IMG src="https://ad.doubleclick.net/ddm/ad/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[ti... BORDER=0 WIDTH=300 HEIGHT=250 ALT="Advertisement"></A>
</NOSCRIPT>

 

How can I do it? where on this code do I need to insert the GA event tracking code? Can anybody help? Thanks for your time and attention.

Re: Adding GA event tracking code to javascript

Participant ✭ ✭ ✭
# 2
Participant ✭ ✭ ✭
Hi ,
First of all the code that you are using is outdated. Event tracking code should be like this -
onClick="ga('send', 'event', { eventCategory: 'testCategory', eventAction: 'testaction', eventLabel: 'testvalue', eventValue: testnumericvalue});"

Please check this post @ http://www.seerinteractive.com/blog/event-tracking-explained/

***Old code is used in above post so you have to change the code rest will be the same**

Hope this helps.

Thanks

Re: Adding GA event tracking code to javascript

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks for your help. I have the outdated code working on some banners, tracking clicks. The code is working with html and I can see events being tracked in real time. It is with the Javascript Banner that I don't find a way to make it work. The outdated or the code you provided. any idea why?

This is what i am doing:

 

<SCRIPT language='JavaScript1.1' src="https://ad.doubleclick.net/ddm/adj/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[t...
</SCRIPT>
<NOSCRIPT>
<A HREF="https://ad.doubleclick.net/ddm/jump/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[... 'event', { eventCategory: 'testCategory', eventAction: 'testaction', eventLabel: 'testvalue', eventValue: testnumericvalue});">
<IMG src="https://ad.doubleclick.net/ddm/ad/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[ti... BORDER=0 WIDTH=300 HEIGHT=250 ALT="Advertisement"></A>
</NOSCRIPT>

 

I appreciate your input.

 

Re: Adding GA event tracking code to javascript

Explorer ✭ ✭ ☆
# 4
Explorer ✭ ✭ ☆
Hi,

Add the GA event tracking code within &lt;SCRIPT&gt;. Thanks.

Re: Adding GA event tracking code to javascript

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Did that. see code. Still not working. Thank for your help.

 

<SCRIPT language='JavaScript1.1' src="https://ad.doubleclick.net/ddm/adj/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[t...
onClick="ga('send', 'event', { eventCategory: 'testCategory', eventAction: 'testaction', eventLabel: 'testvalue', eventValue: testnumericvalue});"
</SCRIPT>
<NOSCRIPT>
<A HREF="https://ad.doubleclick.net/ddm/jump/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[...
<IMG src="https://ad.doubleclick.net/ddm/ad/N115602.2277124SCIENCEOFMIND/B9604916.130371395;sz=300x250;ord=[ti... BORDER=0 WIDTH=300 HEIGHT=250 ALT="Advertisement"></A>
</NOSCRIPT>

Re: Adding GA event tracking code to javascript

Explorer ✭ ✭ ☆
# 6
Explorer ✭ ✭ ☆
It could be because the users are navigated too quickly to the new page / site. You need to either add some delay to the navigation to the new page / site until the event is fired or use GA event tracking transport - beacon method. Check the 2nd paragraph in Outbound link and form tracking in this link - https://developers.google.com/analytics/devguides/collection/analyticsjs/events#examples

Re: Adding GA event tracking code to javascript

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Hi, thank you for your input. It works this way(see below in red), without any delay factor. But the GA code is added to a plain html script. If I add it to the Javascript it will not work, even with transport Beacon included. Any ideas? Thank you.

 

<p><a href="http://www.penguin.com/book/its-never-too-late-to-begin-again-by-julia-cameron-with-emma-lively/9780... onclick="__gaTracker('send', 'event', 'Advertisement', 'http://www.penguin.com/book/its-never-too-late-to-begin-again-by-julia-cameron-with-emma-lively/9780... 'Tarcher Cameron Book');" target="_blank"><img src="http://csl.org/testsomag/wp-content/uploads/2016/03/Tarcher_Cameron_ad.jpg" border="0" height="250" width="300"></a></p>