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
-
How do I track a primary domain and a subdomain as single site in Google Analytics?
Our website consists of a primary domain (marketing focused) and subdomain (ecommerce platform). The two sites look and function as one site even though they are using different technology. I would like to track the primary domain (example.com) and the subdomain (shop.example.com) as a single site in Google Analytics. The subdomain will be set up with GA ecommerce tracking as well. Can someone provide an example of the GA snippet that each would need?
Reporting & Analytics | | Evan340 -
Can't identify the real source of a goal because subdomains in GA
Hello, I have one domain for my website (www.domain.com) where I receive all the new traffic and a subdomain (billing.domain.com) for the billing system. Im tracking both in Analytics. I have a goal (new order) configured in the subdomain -billing system-. But when I want to track the source / medium of the goals (new orders) in billing.domain.com, always appears my main website (www.domain.com) as the referral. Now I added in Analytics: Admin > Property > Referral Exclusion List, the www.domain.com and domain.com. Do you think that now I can track the real referrer of the goals? Or should I do a more complex tracking setup with Tag Manager ( https://support.google.com/tagmanager/answer/6106951 ) to pass the session cookies from a subdomain to another one, just to identify the real source / medium of the visitor? Thank you 🙂
Reporting & Analytics | | estebanseo0 -
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 -
Tracking an onpage 'event'
Hi all Wondering if anyone could help out with this one please. My client is a government backed free internet safety website and in the next few days they will be launching an update on all of their pages which will let people know if their browser is out of date. For example, when you go to their site you will get a message advising you to upgrade your browser for security reasons. They have employed the following code to check the browser The client are keen to know how many times in a period this message is shown to users. Any idea how one would go about tracking this please. Would it involve some custom GA work, would I be able to track the hits on https://wxxxx.org/javascript/update.js in GA? I'm a little stumped. Obviously I can tell how many people loaded the page but not sure how to work out what % of them see the javascript Many thanks for your help Carl
Reporting & Analytics | | GrumpyCarl0 -
Is there a way to use Google Analytics event tracking for YouTube embedded videos on my website?
Hello! I am trying to track different types of interaction on the YouTube for videos which are embedded on a website to measure the interaction on these video from my organic traffic. Is there a good way to go about this with the code since these are coming from an iFrame on YouTube? Would appreciate any feedback or help on implementing the event tracking with YouTube videos. Many thanks!
Reporting & Analytics | | CabbageTree0 -
How can I track search engine optimization data in Google analytics?
My website is linked to a Google Analytics web property. But, I am not able to track search engine optimization data in Google Analytics. So, How can I get it done?
Reporting & Analytics | | CommercePundit0 -
Google analytics tracking
Is their a built-in or easy way to track the amount of times an exit link is clicked on a page and show that with other links of the page. For instance: I had a page with several external ad links on it and I want to track how many each got and rank them in google analytics
Reporting & Analytics | | insitegoogle0 -
Tracking SEO tests
Trying to get some best practices on testing SEO changes. We are going to make a bunch of changes on subsets of pages. Say testing about 5 different on-page changes. Originally we were going to submit separate Sitemaps to GWT and see if our test sets get indexed, how quickly, etc. But we noticed that GWT says some pages in our Sitemaps aren't indexed even though we know they are (what gives?). So we thought, for each test, let's put a unique code on the page so we can see how many get indexed by Google. But that doesn't solve the issue: how many people clicked on our test pages. So we are thinking of putting a tracking pixel on the test pages, specific for each test. But then I am thinking, why not just create a separate Google Analytics profile and place that code on the test pages (set up goals to track visits per test since we aren't going to change the actual URLs). and on and on This is where you come in. What kind of tracking do you implement when you set up tests? Advice appreciated! E
Reporting & Analytics | | ErinTM0