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 to create goal for Events?
Hi All, I have created event via google tag manager for my ecommerce site. That events are button clicks. Now I want to know after clicking that event does that customer reached to Thank You Page or not? How can I do that? which type of goal I have to create? Thanks!
Reporting & Analytics | | pragnesh96390 -
Tracking links and duplicate content
Hi all, I have a bit of a conundrum for you all pertaining to a tracking link issue I have run into on a clients site. They currently have over duplicate content. Currently, they have over 15,000 pages being crawled (using Screaming Frog) but only 7,000+ are legitimate pages in the sense of they are not duplicates of themselves. The client is using Omniture instead of Google Analytics and using an advanced tracking system on their site for internal and external links (ictids and ectids) in the URL parameters. This is creating thousands of duplicated pages being crawled by Google (as seen on their Search Console and on Screaming Frog). They also are in the middle of moving over from http to https and have thousands of pages currently set up for both, again, creating a duplicate content issue. What I have suggested for the tracking links is setting up a URL parameter in Search Console for these tracking links. I've also suggested they canonical all tracking links to point to the clean page so the pages that have already been indexed point to the correct clean url. Does this seam like the appropriate strategy? Additionally, I've told them before they submit a new sitemap to Google, they need to switch their website over to https to avoid worsening their duplicate content issue. They have not submitted a sitemap to Google Search Console since March 2015. Thank you for any help you can offer!
Reporting & Analytics | | Rydch410 -
Implemented Enhance Ecommerce but Event tracking showing double
Hi, Today i have implemented Enhance Ecommerce with GTM everything working fine but in google analytic > Behavior > Events here all events figure i see double - triple so not getting exactly what is the issue. Thanks!
Reporting & Analytics | | varo0 -
Track subdomain in analytics
Hi, Our jobs section has recently been moved on to a subdomain https://jobs.ourwebsite.co.uk/home.html which is handled by a third party. Our analytics for the jobs section was lost as no code was added to the pages. Previously it was part of the main site. How do I track it as a subdomain so that it appears to be part of our main site? We have the old GA and universal GA code on the site Thanks
Reporting & Analytics | | Houses0 -
Tracking Goals on a Subdomain?
What needs to be done to Analytics to track goal completions on a subdomain? The main Analytics profile is set up for example.com, but landing pages for paid campaigns are set up at sub.example.com. Thank-you page is sub.example.com/thank-you.php What needs to be modified in Analytics (or to the Analytics code) or how do the goals need to be set up to track these subdomain conversions all within the same Analytics profile? They're not tracking currently. Thanks.
Reporting & Analytics | | elcrazyhorse0 -
Reported data in Multi-channel funnels in GA wrong?
I'd love to start using the Multi-channel funnels feature in Google Analytics but I have zero confidence in the reported data as it seems to bear no relationship to the standard ecomm reports. To be specific, in August 2013, MCF is reporting the following for email campaigns: Assisted conversions = 20
Reporting & Analytics | | Bluesnapper
Assisted conversion value = £1,405.91
Last Click or Direct Conversions = 14
Last Click or Direct Conversion Value = £369.57 Now switching to the traffic sources report, GA reports for the email campaigns revenue was £1,226,41 over the same period across 21 transactions. My interpretation of this is that the email campaigns were the "last-click" and delivered £1,226,41 and 21 "conversions" (as I have no goals configured in this GA view, conversions = transactions I believe) That leaves the MCF last-click report short by £856.84 (£1,226,41 - £369.57) I can see no reason why this should be so unless I'm not interpreting the data correctly! Anybody have any suggestions/ideas as to what's going on? Any help appreciated.0 -
GATC New code structure?
Hi Guys, One of my clients has this code showing up, and it is receiving data! Is this normal? First time I ever see such a code! Thanks for clarifying!
Reporting & Analytics | | Ideas-Money-Art0 -
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