How to use trackPageview in Google Analytics? - javascript

I need help in configuring the _trackPageview in the Google Analytics. I want to track how many times a file has been downloaded. According to Google Analytics documentation I need to use the following onClick event in the download links.
<a href="http://www.example.com/files/map.pdf"
onClick="javascript: _gaq.push(['_trackPageview', '/downloads/map']);">
But I could not find any information that after adding this, where I can see the download stats for this link? Do I need to configure anything in my Analytics account? Thanks.

That should work, and you shouldn't need to configure anything in Analytics. You will not see the events appear in the Analytics account immediately. I'd give it 24-48 hours to start showing up.
All clicks should be tracked from when you install the code. It may show up under Top Content, or you could filter visited pages by a partial URL.
Because of the delay inherent to Analytics, it's not uncommon to second-guess yourself when you try a new tracking technique. It's important to follow up and confirm the events are registering.
Edit: More info regarding _trackPageview vs _trackEvent...
_trackPageview: "Google Analytics' _trackPageview is a function for use on ga.js tracked sites that allows you to track events on your site that do not generate a pageview."
_trackEvent: "Event Tracking is a method available in the ga.js tracking code that you can use to record user interaction with website elements, such as a Flash-driven menu system."
My suggestion is that if you have a number of different downloadable files that you want to track, look into _trackEvent. If you only have one or two files to track, _trackPageview is definitely suitable. My thought is that when you have a larger number of files to track, _trackEvent will let you track by category (file download), action (hyperlink click), and label (map), which may be more useful if you're interested in downloads as a whole.
_trackEvent is also ad hoc in that whatever you code you write should auto-generate the corresponding report items without any configuration in Google Analytics.
More info (above quotes taken from these pages):
_trackPageview: http://support.google.com/googleanalytics/bin/answer.py?hl=en&answer=55597
_trackEvent: https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

If you want to make sure your tracking is working but don't want to wait 24-48 hours then go to the Real-Time (beta) tab in the Google Analytics sidebar.
Visit the website on another tab and, once you see that the 'Right now' indicator shows your presence, click on your download link. If you see it show up in the 'Top Active Pages' then you're good to go, gilded and golden.

You can also use the debug version of ga.js to diagnose errors. It prints things like "Invalid tracking code" and so on to the Javascript console.
Search for "Debugging with ga_debug.js" on this page:
https://developers.google.com/analytics/resources/articles/gaTrackingTroubleshooting

Related

Artificial pageview pushed to Analytics is changing PPC traffic source

So basically, we are having issues with a website (https://thesoundshop.com) in which the PPC traffic source (it only seems to be PPC traffic that is affected) is being changed by the pageview that we are pushing through to analtics.
The website runs on Ajax so we have to use Javascript to emulate pageviews through to Analytics whenever a link is clicked on the website. We are not using Google Tag Manager to implement the analytics or javascript because of this so we are using the gtag method exactly as Google's documentation recommends:
gtag('config', 'GA_TRACKING_ID');
I have tested this by visiting the website through a PPC ad and watching the real-time reports in Analytics. The first page load attributes the correct source to the traffic (cpc) as expected but then when I click on a link to go to a different page, the traffic source changes to Google Organic search. I then complete an action that I know will trigger an event or a goal and then when this appears in the Goal Reports, it attributes the goal as organic, too.
We know that this has to be down to the Javascript pageview that is being pushed to analytics to simulate that a new page has loaded but we can't work out why it would be changing the traffic source. The gtags are implemented exactly as Google recommends; just wondering if anyone else has had this problem and if so, how did they go about fixing it?
We had the same issue and after some more research found the problem along with the solution, thanks to Simo.
Basically, you need to manually set the document.referrer of the first session to make sure it persists and does not get over-written half way through the session. It's a known issue with GTM and single page applications.

De-bugging Google Analytics Link & Download Tracking

I'm trying to install some script on one of my websites to track outbound links and downloads in Google Analytics but I'm not having much luck. This is the script that I'm using (if anyone knows of a better guide or script I'd love to hear about it).
My question is this: How can I check whether it's working without using Google Analytics? Is there a way I can see the events or data that's being sent when a link or download is clicked using Firebug or Developer Tools?
Thanks in advance,
Tom
You might use the GA autotrack plugins instead (https://github.com/googleanalytics/autotrack) - while not an "offical" part of the product those are written by a Google engineer (who also maintains some presence at stackoverflow).
However it is easy to see if this works - Google offers the Google Tag Assistant (for Chrome) to test GA integrations, there is a Chrome GA Debugger Extension, or you might simply open the developer tools in your browser and inspect the "network" tab. If you filter for calls to google-analytics.com/collect you should see outgoing calls and can look at the query parameters to see if your data is sent properly; if the calls return a http status of 200 the data should turn up in your GA account.
Thanks to Eike's response I've now chosen to solve this challenge by installing Google Tag Manager and then creating custom tags to track things like outbound links, email links and download links. Here's a guide that helped me to setup download tracking, hope others find it useful.

Google Event tracking for phone number

I am running a WordPress site, which is verified with Google Webmaster Tools and has a GA code associated with Google Analytics.
I've done some research on the web to add an Event tracker for clickable phone numbers in mobile, so that I can measure how many people actually use the phone number on the homepage of the website we developed for a client: posanarestaurant.com.
Most of the blogs that offered up how to do this simply gave me this code to add to my site below:
828.505.3969
They said that Google would start to pick up tracking in 24 to 48-hours, but I haven't seen anything in GA yet.
I know that there is some javascript that might go in the head of the site, but one of the plugins I'm using already adds that javascript, so I don't want to duplicate having two exact same javascript references in the head of the site.
What am I doing wrong?
The syntax for UA event tracking is
ga('send', 'event', 'Phone Call Tracking', 'Click/Touch', 'Home Banner')
So your complete code would be
828.505.3969
Once you have that set, and if you are not filtering out your own views, you can check for the event hit in Real-Time reports (so you don't have to wait 24 hours to see if it's working).

Conflict with double google analytics

I have a website that only has a full window iframe to a page that already has google analytics, but not on my account(the page isn't mine either). I would like to track my website with Google Analytics and if I put the script in the head site it will say "Tracking not installed". IS there any way to make the browser ignore the google analytics from the iframe?
If the iframed GA account isn't yours then there is nothing you can do about it. However you can still implement your own analytics by simply doing what you were doing before and putting your own GA code on your pages. You will see that tracking not installed message because it normally takes at least 24 hours for the code to register. In the meantime if there is nothing else wrong with the implementation, you can check in your Real-time reports to see if your own simultaneous visits are recorded. If they are then you are good to go and just need to wait 24 hours for data to show up in your standard reports.
You cannot change the content of the iframe, it would violate the same origin policy. Are you sure you should be using an iframe at all? Either way you can easily add Google Analytics to your own site and track whatever you need with your own Google Analytics ID.
If your analytics code is in the iframe, Google will report that tracking isn't installed as they're checking the parent page, not the iframe. Tracking will still work, though. You should see stats come through normally.

google analytics tracking link clicks

I was wondering how would i go about adding a simple tracking to a certain link on a site I am developing for a client
I am using google analytics for tracking the source of the incoming traffic and after the visitor has entered the site he supposed to click on a link, I an interested in knowing how many clicks I got from every source.
You're looking for "Campaigns". There's an extensive article about it here: http://support.google.com/analytics/bin/answer.py?hl=en&answer=1239239
You can use the "URL Builder" tool to create a URL for a specific link (on an external site, presumably) by giving a name to your campaign and other details. The parameters are utm_source, utm_medium, and utm_campaign in particular.
I'll mention that Analytics will already tell you (without any modification to the link) what referring page sent a visitor, so you can tell what page a visitor was viewing before arriving at your site. All this is found under "Traffic Sources" in the Analytics reporting interface. The utility of campaigns is if either (a) you'll be scattering links in ads on many different websites, and it's the ad rather than the page that you want to track, or (b) there may be multiple links to your site on the same page and you want to know which one the visitor clicked.

Categories