Google Analytics and tracking unique downloads

I have a resource page with .pdfs and .ppts
What do I need to do to track if a user clicks on these links?
Is there also an extra step I need to take to track if they successfully downloaded the target completely?

I heard one solution is to make a single sub-web page for each download item and stick an analytics snippet in to the page as one way to track, but this sounds tedious and not very efficient. Is there something that can track this on the fly?

Thanks!

Posted on May 4, 2010 8:40 AM

Reply
52 replies

May 4, 2010 9:05 AM in response to Yoga_D

You can track downloads, but you cannot track what your visitors will do with it.

To track download you have to use a filesharing service that keep these records. Or ask your webhoser (not MobileMe) if they provide a service.

And yes, Google provides this. Which you find tedious.

http://www.goodwebpractices.com/roi/track-downloads-in-google-analytics-automati cally.html

Shop around : http://www.google.com/search?q=track+downloads

May 13, 2010 7:46 AM in response to Wyodor

Wyodor,

Thank you for your response. I've found the time to tinker with this subject again. So I implemented the goodwebpractices.com instructions. According to them, i add the gatag.js before the new ga.js (not the old urchin.js), create a scripts/ directory and copy gatag.js to it (I checked that it was readable and it also loads in firebug) and then I waited impatiently 24+ hours for Analytics to update.

At this point I want to make an observation mixed with opinion here.
Using Analytics in conjunction with the iWeb structure is confusing. The HTML snippets show up as widget aka separate html pages in Analytics:
http://somaticjourney.com/Contentby_Title_Detail__-_GoogleAnalytics-20100513-103756.png

Back to the topic, so Analytics is not showing any signs of tracking unique downloads (courtesy of gatag.js). I did a further search on the topic and found from this source ( http://www.google.com/support/forum/p/Google+Analytics/thread?tid=658eefb13de9d4 36&hl=en ) which is saying in opposition to goodwebpractices.com that gatag.js goes AFTER ga.js
So I've followed their advice and am waiting to see what happens.

May 13, 2010 4:41 PM in response to Yoga_D

this is known issue with using html snippet and complex javascript to track web page activities.
you have several options:

1) adding the code directly on the page by post editing, every time you make changes to it.
2) use html snippet and mentally juggle the analytics data, see Basiliskus' post:
http://discussions.apple.com/message.jspa?messageID=8953867#8953867
3) digging into google javascript and iweb structure, and build your own GA widget.

May 14, 2010 4:17 AM in response to Cyclosaurus

So the main issue here is:
gatag.js (Google Analytics script that tracks individual downloads) doesn't function due to it being placed in an HTML snippet which upon creation is appended to a whole different other html page within the iWeb subdirectory (specifically: Resources files/widget1markup.html). So essentially the script is tracking an empty page!

I've included a portion of the HTML from the page (which has the files I wish to track) here I want to add the javascript to. Can someone tell me what I can omit from from the former which calls widget1_markup.html and in it's stead put the latter? Thank you very much.

BTW, I'm leaving Apple iWeb some feedback about this problem. http://www.apple.com/feedback/iweb.html

Message was edited by: Yoga_D (2nd attempt at posting re-edit)

May 14, 2010 4:48 AM in response to Yoga_D

Below is the feedback I left apple iWeb team using their feedback form. I invite anyone to send their variation of the below message to http://www.apple.com/feedback/iweb.html

When an HTML snippet is created it creates a separate .html in which the contents of the widget is appended to. The widget is then called in to it's parent html file. Google Analytics has a script called gatag.js that tracks unique downloads -within- the page that it is placed. As you can see, this raises an issue when adding gatag.js in to an iWeb HTML snippet it's actually tracking an empty page (widget1.html) instead of tracking the page it is being called in to.

Can apple create a workaround (example: a gadget) that circumvents this issue?
and fix this in the next version of iWeb ?

Thank you

May 14, 2010 6:28 AM in response to Yoga_D

Here's a solution that may work. Just tried it today. May see results tomorrow.

Get the Google analytics code.

Open TextEdit and set it to plaintext.

Paste the code WITHOUT these opening and closing tags :

<script language="JavaScript" type="text/javascript">
<!--
// -->
</script>


Save the file as analytics.js

Put the file on the server and determine the URL to it.

Create a blank page (for testing) and paste this code in a HTML Snippet.

<script language="JavaScript" type="text/javascript">
<!--
var headID = parent.document.getElementsByTagName("head")[0];
var newScript = parent.document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = '../js/analytics.js';
headID.appendChild(newScript);
// -->
</script>


Where it says *newScript.src = '../js/analytics.js';* use your own URL.

Publish the page.

Visit your page and open the Activity window in Safari (Comand-Option-A)

Note the 2 URLs to Google. They look the same as with code that is pasted in a page.

Tomorrow check with Google to see if your page appears in the stats.

Call your friends and family and tell them to visit the page. More visitors may show more results.

If it works, fine.

If not, then I'm mistaken and will sob in a corner.

May 14, 2010 11:49 PM in response to Cyclosaurus

You see the results the next day. Didn't you know that?

Anyway, here are the results of yesterday, Friday 13 May, when I added the code.

It works as predicted :

!http://www.wyodor.net/ Discussions/AnalyticsBrowserOS.png!

!http://www.wyodor.net/ Discussions/AnalyticsTitle.png!

!http://www.wyodor.net/ Discussions/AnalyticsPages.png!

Note that the widget file also shows. It was a false start.

Check it here : http://ipad.dailynews.webege.com

May 15, 2010 10:33 AM in response to Wyodor

Wydor, before I continue I want to acknowledge the work you've done. Thank you for that.

As for the post, I'll try what you propose. I want to confirm that analytics.js looks like this: (notice the part of the script that calls gatag.js is that going to be an issue?)


var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = gat.getTracker("UA-6713948-1");
pageTracker._trackPageview();
} catch(err) {}
<script src="http://www.energyschool.com/scripts/gatag.js" type="text/javascript"></script>

May 15, 2010 11:15 AM in response to Yoga_D

The code you use is not entirely correct.

The analytics tool also has newer code. I used that in my method.

The older code you show here does not work that way.

Here's the page that explain it :

http://www.google.com/support/analytics/bin/answer.py?answer=174090

According to the article you had to use it anyway.

I didn't take the gatag.js code into account. It looks rather easy to implement too.

Allow me to find out what the best way is to put it in place.

May 15, 2010 11:34 AM in response to Wyodor

Here's the code you paste in the HTML Snippet :

<script language="JavaScript" type="text/javascript">
<!--
var headID = parent.document.getElementsByTagName("head")[0];
var newScript = parent.document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = '/js/gatag.js';
headID.appendChild(newScript);
var headID = parent.document.getElementsByTagName("head")[0];
var newScript = parent.document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = '/js/analytics.js';
headID.appendChild(newScript);
// -->
</script>


It puts the gatag.js before the Google code as per instructions here :

[Tracking downloads automatically|http://www.goodwebpractices.com/roi/track-downloads-in-google-ana lytics-automatically.html]

Both the gatag.js and analytics.js files should be in the same place on your server. Mine is the js folder.

Note that analytics.js is the name I gave to the file as explained earlier. It's not what Google provides. I only pasted the Google Code in it.

I use it on the iPad welcome page. Be so kind to download both jpg files you see there. I did already. Now I have to wait till tomorrow to see if it shows in the analytics page.

Midnight is 3,5 hours away here, so be patient 🙂

May 15, 2010 1:43 PM in response to Wyodor

Wyodor,

So I followed your awesome advice and now I'm waiting as well for Analytics to update. I d/led the to images from your iPad site as well.

I checked your setup using firebug and found that our analytics.js and gatag.js are identical (save for the special UA#)

I'm hoping the javascript comments in gatag.js don't fudge the process up.

Waiting patiently,
Yoga_D

May 15, 2010 4:16 PM in response to Wyodor

The downloads won't show in the stats.

After some testing I discovered the script loads to early ignoring links in the page.

I now use the code below in the HTML Snippet. Instead of putting the scriptlinks in the <head> it now puts them at the end before the </body>. The gatag.js script now counts the links in the page.

var bodyID = parent.document.getElementsByTagName("body")[0];
var newScript = parent.document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = '/js/gatag.js';
bodyID.appendChild(newScript);
var newScript = parent.document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = '/js/analytics.js';
bodyID.appendChild(newScript);


Have to wait another 24 hours to see the results.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Google Analytics and tracking unique downloads

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.