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
-
Google Analytics - Events impacting session data
Hi Mozzers, Has anybody ever experienced event tracking significantly impacting session data? Here's a summary of what I'm finding: When I measure sessions to a particular hostname (a subdomain) in my Google Analytics report, sessions dropped by over 100% when I removed some event tracking on that subdomain (an event was triggered when a user clicked on a particular button). When I reinstate that event tracking, sessions go back up to around where they used to be. Can anybody understand why this might be happening? Thanks!
Reporting & Analytics | | A_Q0 -
How do I get compete.com to track my data
Is there a tracking code for them? I cannot find a way to get them to track my site data. I know it seems trivial, but it is sadly a big tool in my industry so I need to get my data on their site
Reporting & Analytics | | Atomicx0 -
No Google Analytics code on page BUT reporting is active
How could Google Analytics be reporting data if my pages don't have the GA code on them? Mike
Reporting & Analytics | | Mike_c0 -
Google Analytics: How to Track Blog Traffic that Enter the Purchase Funnel?
I've been trying to figure this out for awhile, but I have had no luck. The current ecommerce store that I work for is trying to find out how to track how many people coming in via the blog are converting/buying. The site lives on Magento and the blog is on wordpress and they both use the same Google Analytics code. Site URL: http://website.com/ Blog URL: http://website.com/blog Is there anyway to do this so you can see which landing pages are driving conversions? If not, Is it possible to set up Google Analytics to show conversions and revenue coming from people who enter through blog directory?
Reporting & Analytics | | Erik-M0 -
Google analytics is not tracking well
Hey, There is something not working in our GA account, its shows too many visits per day, when look where this traffic comes from, the majority comes from (not set). Please find attached. Really appreciate help! Thank you! BvmAKtO
Reporting & Analytics | | Comunicare0 -
What keywords are called conversion keywords? how do you track them ?
I have tried more than 200 keywords to optimize Akshaya Patra website, but i am finding it difficult to analyzie the lead /convesrion keywords to rank our website at the top of search results. How many keywords do you suggest for conversion , how do you utilize the keywords to ensure we are ahead of the competitors We are a nonprofit organisation, HQ is in India, our main focus is to feed underprivieled children in India website URL www.akshayapatra.org
Reporting & Analytics | | AkshayaPatra0 -
Google analtyics code placement
I saw that Google suggests the analytics code be in the , will this effect the page load if it is in here? Also, is it a problem to have it in the body?
Reporting & Analytics | | Gordian0