Where should I insert the code when I track an event on GA?
-
hi mozzers,
I am trying to setup my first event to count the numbers of downloads of an infographic(pdf file) we just created on GA and after some research I figured that I should add this piece of code (below) but where exactly?
<colgroup><col width="386"></colgroup>
|_gaq.push(['_trackevent', 'PDF', 'Download', 'name of file']);
|
Should I put it just in between _gaq.push(['_setDomainName', 'coit.com']); and _gaq.push(['_trackPageview']); ?
Please provide details because I ve never done this before
Thanks
-
About "return false", you may read this: http://stackoverflow.com/questions/128923/whats-the-effect-of-adding-return-false-to-an-onclick-event
This is a good explanation.
v_ls function only adds a little time to wait in order to allow Google Analytics to store data.
-
Thank you guys for this answer!
In summary I have to put this code in the header of the link that carries the pdf file? (As you can see I am not a mastermind in coding...haha)
@Max: Do i have to plug this piece in order for it to work, if so why? because I read quiet a bit of articles and none of them mention a "return false" or any of the bigger piece you added(below)?
function v_ls(link, category, action) {
try {var myTracker=_gat._getTrackerByName();_gaq.push(['myTracker._trackEvent', category , action ]);setTimeout('document.location = "' + link.href + '"', 100)}catch(err){}};
Thanks Guys
-
-
David, a "return false" is missing for some browser. A timeout too (recommanded by Google in order to save all tracked event):
Try this:
And add in header this javascript function:
function v_ls(link, category, action) {
try {var myTracker=_gat._getTrackerByName();_gaq.push(['myTracker._trackEvent', category , action ]);setTimeout('document.location = "' + link.href + '"', 100)}catch(err){}};
-
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Google Analytics - Tracking multiple thankyou pages?
Hi Guys, I want to track email opt-ins for multiple thank you pages. The setup is as follows: http://image.prntscr.com/image/57632e05a15f42fda0b8ffec2d176460.png I have not yet built the thank you pages, so i was wondering what the URL should be to make it easy to track them in GA? I'm thinking: domain.com/thankyou-page/page1 Then using regular expression in GA to track /thankyou-page/ Would this be a good way to go about it? Cheers. f6c7r0
Reporting & Analytics | | spyaccounts110 -
Big discrepancy between GA an GSC
Hey! I would really appreciate if someone could help me on this 🙂 I have a website with separate mobile and desktop versions, on GSC I see a huge drop in the number of clicks on the mobile website and an increase in the number of clicks on the desktop website, however this isn't reflected at all in GA. GA shows that mobile traffic hasn't increased for any version of the website and the webpages losing traffic according to GSC are flat/growing on GA (even if I look at traffic coming from organic only). Has anyone experienced something similar or has any possible explanation? Thanks!
Reporting & Analytics | | Anna_90 -
We have a client that wants to apply UTM URL tagging to track local organic traffic in Google Analytics. Is there any benefit in doing this?
One of our clients requested that we apply UTM URL tagging to better track organic traffic in Google Analytics. We found this to be an odd request because we are most familiar with UTM tracking for special campaigns (referral tracking, PPC, email tracking, etc). Is there any benefit of applying UTM tags to urls to analyze local organic traffic in Google Analytics? Are there any resources out there about this? Thanks!
Reporting & Analytics | | RosemaryB0 -
Does Google Analytics track conversions in real time?
Looking at the section: Conversions > Goals > Overview - does Google Analytics provide real time / same day metrics for this conversion data or does it take 24 hrs?
Reporting & Analytics | | Rich_Coffman0 -
Installing Google Analytics tracking code on Landing Pages
Hello, I have my landing pages located on a separated subdomain (LP.example.com). I've created a new property in Google Analytics for that subdomain. My question is: where do I have to place the GA tracking code ? in the header ? before I close the tag or before I close the tag ? I have another issue: I've placed the GA Tracking code on some pages in the way below:
Reporting & Analytics | | JonsonSwartz
in the body tag of that Landing page HTML Code I added this line:0 -
Newsletter tracking event GA- Magento
Hi there, I am trying to track an event, newsletter signup in this case, on my Magento store. I added onClick="_gaq.push(['_trackEvent', 'Microconversion', 'Evento_Onclick', 'Sus_Newsletter']);" on subscribe.phtml Category: Microconversion Action: Evento_Onclick Label: Sus_Newsletter It doesn't work, it's does not track this event. What am I doing wrong? Thanks and regards
Reporting & Analytics | | footd0 -
Cross Domain Tracking
I want to track across domains, but also track as a virtual pageview anytime someone clicks on the link to another domain. So currently I have, for example: Checkout Now! As per Google's instructions, I need to have the link set to: Checkout Now! But this will obviously get rid of my virtual pageview. Is there a way I can do both?
Reporting & Analytics | | TeachersMutualBank0 -
Tracking on Analytics .ca domain When Redirect From GoDaddy Control Panel?
I bought all .ca, .net, .org, .info and http://www.pilatesboisfranc.com at GoDaddy. I'm using .com and all others are redirect to the .com from the GoDaddy control panel. Is it easy to track any of thems on Analytics? I just installed the tracking code and I selected in the ''What are you tracking'' option from the ''Advance'' tab, '' Multiple top-level domains
Reporting & Analytics | | BigBlaze205
Examples: www.pilatesboisfranc.uk
www.pilatesboisfranc.cn
www.pilatesboisfranc.fr If someone enter http://www.pilatesboisfranc.ca will it be track? I don't know anything about coding, I hope you can help because I would like to use the .ca doamine to track advertising on my car... Thank you, BigBlaze0