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
3.8K members online now
3.8K 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

Where do we place var _gaq in GA tracking code to track document downloads?

Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆
I am trying to add the gaq snippet to the GA code on my page, and I am not sure where to put it exactly. We recently had our site redesigned and our Documents Downloaded tracking has stopped working. This seems to be the culprit. Right now, I have the standard GA tracking code placed on my site.
 
 
 
This is what I need to add to it (I think??):
 
var _gaq = _gaq || [];
_gaq.push(['myTracker._setAccount', 'UA-MY#HERE']);
_gaq.push(['myTracker._setDomainName', ‘MYWEBSITE.COM’]);
_gaq.push(['myTracker._trackPageview']);
 
 
How I'm tracking in links:
 
a class="btn btn-primary" href="url" onclick="_gaq.push(['_trackEvent', 'button', 'downloaded', 'name of product sheet']);"
 
 
Anyone's help is greatly appreciated! Hope this makes sense..
1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Daphne S
March 2017

Where do we place var _gaq in GA tracking code to track document downloads?

Top Contributor
# 6
Top Contributor

Hi,

 

Your code for the button should look like this:

 

<a class="btn btn-primary" href="http://go.gspretail.com/success-stories/GSP-Pharmacy-SS" onclick="ga('send', 'event', 'button', 'downloaded', 'name of product sheet');" target="_blank">Download PDF Version</a>

 

Let me know if it works.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital

View solution in original post

Where do we place var _gaq in GA tracking code to track document downloads?

Top Contributor
# 2
Top Contributor

Hi,

 

Your code above is outdated, it is recommended to use the current Universal Analytics version. You can find the tracking code in GA Admin -> Property -> Tracking Info -> Tracking code. Once ready, you can set up tracking download link clicks like:

<a class="btn btn-primary" href="url" onclick="ga('send', 'event', 'button', 'downloaded', 'name of product sheet');">link</a>

Hope this helps, let me know if you need help with it.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital

Where do we place var _gaq in GA tracking code to track document downloads?

Follower ✭ ☆ ☆
# 3
Follower ✭ ☆ ☆

Thanks, Arnold. I've gone ahead and updated the main code.

 

What do I now add to this code to start tracking "onclicks" or my downloaded documents?

 

 

Where do we place var _gaq in GA tracking code to track document downloads?

Top Contributor
# 4
Top Contributor

Hi,

 

You need to add the onlick code to the html code of the download button:

onclick="ga('send', 'event', 'button', 'downloaded', 'name of product sheet');"

 

If you can post your site URL where the button is or the button code I'll be glad to help with it.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital

Where do we place var _gaq in GA tracking code to track document downloads?

Follower ✭ ☆ ☆
# 5
Follower ✭ ☆ ☆

That is how I have the code, but it wasn't tracking. Will this new GA code, since I had the wrong version, take care of that?

 

<a class="btn btn-primary" href="http://go.gspretail.com/success-stories/GSP-Pharmacy-SS" onclick"_gaq.push(['_trackEvent', 'button', 'downloaded', 'success story - pharmacy']);" target="_blank">Download PDF Version</a>

 

 

Marked as Best Answer.
Solution
Accepted by topic author Daphne S
March 2017

Where do we place var _gaq in GA tracking code to track document downloads?

Top Contributor
# 6
Top Contributor

Hi,

 

Your code for the button should look like this:

 

<a class="btn btn-primary" href="http://go.gspretail.com/success-stories/GSP-Pharmacy-SS" onclick="ga('send', 'event', 'button', 'downloaded', 'name of product sheet');" target="_blank">Download PDF Version</a>

 

Let me know if it works.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital

Where do we place var _gaq in GA tracking code to track document downloads?

Follower ✭ ☆ ☆
# 7
Follower ✭ ☆ ☆

Thank you, I've updated my downloadable links to this format. I am hoping by the end of the week I have some sort of data to show that this fixed the problem.

 

Will keep this thread updated.