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){}};
-
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
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
-
UTM tracking on a mapped subdomain, is it OK? (DA bonus question)
Hi, This is a technical question. OK, two technical questions. Please bear with me and I'll do my best to explain... We have a WordPress blog (business account, hosted by WordPress). We use it to blog and send traffic to our separate e-commerce site. We use UTM tracking to see which blog posts perform best. Our e-commerce site has a high domain authority. Our blog, not so much. In an effort to increase the domain authority of the blog we have mapped a subdomain of the e-commerce site to the Wordpress blog (still hosted by WordPress). Q1. Will this actually raise the blog's DA? If the blog does get a DA boost, I guess it'll be because Google now sees it as part of a powerful domain. But if it is technically part of the powerful domain... Q2. Should we remove the UTM parameters from the blog? I've read that you should never use UTM on internal links because it messes with your Google Analytics data. But I'm unsure if links on a mapped subdomain count as 'internal links'. Any help would be gratefully appreciated. Thanks in advance. J
Reporting & Analytics | | JabeKay0 -
What Analytics Do You Use To Track IOS and Android?
We have about 600k downloads of our app and would like to know what cost effective analytics tool you use to gain insight into what your app users are doing? Thanks! Best... Mike
Reporting & Analytics | | 945011 -
404 Status Codes in Google Search Console
Hi all, I've noticed in Google Search Console under 'Crawl errors' - 1. Why does the status code '410' come up as an 'error' in the crawl report? 2. Why are some articles labelled as '404' error when they have been completely deleted and should be a '410' - there are roughly around 1000-2000 of these. Thanks!
Reporting & Analytics | | lucwiesman0 -
Tracking sessions from a sub-domain that is 301 redirected to main domain
Hi, one of my client is launching a new site on a subdomain newsite.brand.com.au but will use a shorter URL on the packaging on their new rang of products to be sold in supermarkets, prompting shoppers to visit xxx.brand.com.au. This specific sub-domain xxx.brand.com.au will be 301 redirecting to newsite.brand.com.au How can I identify and track accurrately all the visits coming from xxx.brand.com.au to newsite.brand.com.au?The visits from sub-domain xxx.brand.com.au will be attributed to direct channel I guess. Is it worth adding GA on this 301 redirected sub-domain xxx.brand.com.au or there another way to identify those visits on newsite.brand.com.au ?
Reporting & Analytics | | mecglobal0 -
Page Name Tracking - Without UTM links
Hello, Our current site is fully html with no cms. We're moving to a newer version today with a typo 3 cms. My one worry is as follows; On some pages an internal link opens a jquery lightbox, inside the lightbox will be a video or download link. I cannot simply add a standard event url like I wanted to (utm_ link) as the pages are linked via the cms pointing to different pages, not the url's. We really need the following appearing in Analytics, whether its an event or landing page; The click of the light-box link The click of the video OR download link inside the lightbox. I would really, really appreciate any help on this as the new website is going live today, regardless whether this has been resolved. Thank you very much in advance of any replies. twY8s8B.jpg
Reporting & Analytics | | Whittie0 -
Has GA changed how it calculates bounce rate?
Updated website from Magento backend to Wordpress and since the redeploy, my bounce rate has dropped from 40% to 4%. I did check to see if there was duplicate GA tracking code but only one call. I checked reports under "visitor flow" and one page visits seem inline with the previous bounce rate. Weird. Never experienced this before.
Reporting & Analytics | | Timmmmy0 -
How do I set up goals in analytics to track the sales funnel when several pages of the steps required to checkout have the same url?
I have found this in Google Analytic but it makes no sense to me - is there are better resource which explains how you do this step by step ( or a good video perhaps?) Identical URLs Across Multiple Steps In some situations, the URL does not change across a sequence of activity. For example, a sign-up process might have the following URL path: Step 1 (Sign Up): www.example.com/sign_up.cgi Step 2 (Accept Agreement): www.example.com/sign_up.cgi Step 3 (Finish): www.example.com/sign_up.cgi To track visitors' progress through a funnel with the same URL for each step, modify the tracking code to create a virtual URL for each step in the sequence that you want to track. For details on how to use this in your tracking code, see Virtual Pageviews in the _Asynchronous Migration Examples_guide, which shows how to do this in all versions of the tracking code. The following example shows how you might fabricate 3 URLs using the asynchronous tracking code: _gaq.push(['_trackPageview', '/funnel_G1/step1.html']); _gaq.push(['_trackPageview', '/funnel_G1/step2.html']); _gaq.push(['_trackPageview', '/funnel_G1/step3.html']); You would then define your funnel and goal URLs using the ones you created in the tracking code modifications.
Reporting & Analytics | | pookiepro0 -
Tracking page visits
Hi guys After a lot of effort and late nights our website has gone online. http://www.health2000.co.nz/ In google Analytics am I able to see what pages individuals clicked on before they went to the cart? Ive had a look at GA 'Flow Visualsiton' but it seems a little confusing. Thanks for your help Pete
Reporting & Analytics | | dawsonski0