Analytics
4.6K members online now
Understand information in your reports and troubleshoot reporting issues such as self-referrals, (not set) data, and inaccurate information
 
Guide Me
star_border
Reply

Web site usage statistics

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I want statistics showing the number of visits to files on my web site.  These files are in doc, htm, pdf, xls anf zip formats.  (An added bonus would be to also see the originating url.)  I have tried, but failed, to understand GA help.  Quite simply it all seems too complicated with technical terms I just don't understand for what seems to be an uncomplicated outcome.

 

Can someone please offer me a simple step-by-step dummies guide solution to my problem?

 

<edited by a Community Manager as noted below>
 
Note: this post has been edited by a Community Manager, per Community Guidelines, in order to remove account specifics and/or personal contact information. This is done to protect account security and privacy. 
1 Expert replyverified_user

Re: Web site usage statistics

Top Contributor
# 2
Top Contributor
Hi Bill :-)
Do visitors access those files via download links that are on your website?
Or do they download them directly from your hosting without having to visit a site page/click a link to access them?
Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Re: Web site usage statistics

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
I think I understand your question. I have two HTM files (for which the urls are 'advertised'). They both include embedded links to other files in DOC, PDF, XLS and ZIP formats. I am looking to get the number (per day) of visits to each of these files whether they are go there directly or via a redirection link. I would also like to capture the url from which the enquire came if at all possible.

Re: Web site usage statistics

[ Edited ]
Top Contributor
# 4
Top Contributor

Hi :-)
For the embedded links, they can be tracked using GA Event Tracking. This can be automated to a certain extent so as to not have to edit every single link in order to track when a site visitor clicks a link to download a file

 

Your site needs to have the current version of the tracking code before the closing </head> tag.

 

The following bolded code is where you edit what file extensions you want tracked
zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav

 

This also requires jquery to be set on the relevant site pages and then the following code after it:
<script type='text/javascript'>
if (typeof jQuery != 'undefined') {
var filetypes = /\.(zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav)$/i;
var baseHref = '';
if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');
var hrefRedirect = '';

jQuery('body').on('click', 'a', function(event) {
var el = jQuery(this);
var track = true;
var href = (typeof(el.attr('href')) != 'undefined' ) ? el.attr('href') : '';
var isThisDomain = href.match(document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]);
if (!href.match(/^javascript&colon;/i)) {
var elEv = []; elEv.value=0, elEv.non_i=false;
if (href.match(filetypes)) {
var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
elEv.category = 'download';
elEv.action = 'click-' + extension[0];
elEv.label = href.replace(/ /g,'-');
elEv.loc = baseHref + href;
}
else track = false;

if (track) {
var ret = true;

if((elEv.category == 'download') && (el.attr('target') == undefined || el.attr('target').toLowerCase() != '_blank') ) {
hrefRedirect = elEv.loc;

ga('send','event', elEv.category.toLowerCase(),elEv.action.toLowerCase(),elEv.label.toLowerCase(),elEv.value,{
'nonInteraction': elEv.non_i ,
'hitCallback':gaHitCallbackHandler
});

ret = false;
}
else {
ga('send','event', elEv.category.toLowerCase(),elEv.action.toLowerCase(),elEv.label.toLowerCase(),elEv.value,{
'nonInteraction': elEv.non_i
});
}

return ret;
}
}
});

gaHitCallbackHandler = function() {
window.location.href = hrefRedirect;
}
}
</script>

 

Generally, files that do not have links embedded in a page are not tracked by GA.

 

Reference - Code modified from linked article

http://www.blastam.com/blog/index.php/2013/09/howto-track-downloads-links-universalanalytics

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Re: Web site usage statistics

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
I have embedded html code in both HTM files and Google is picking that up. I think you are saying I need not do that if I embed zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav. I have not been able to find how to embed code in DOC, PDF, XLS or ZIP files.

As for the instruction "This also requires jquery to be set on the relevant site pages and then the following code after it:" I'm afraid I'm lost again.

You have told me what to do but I how can I do it? (I certainly need a step-by-step Dummies Guide.)

Thanks.

Re: Web site usage statistics

Top Contributor
# 6
Top Contributor
Hi :-)
Are you able to provide a link to one of the htm pages so i can have a quick look at it via my browser?

Thanks :-)
Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Re: Web site usage statistics

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
Bronwyn,

I can get statistics via GA (by embedding code) in HTML files

START CODE
Script – Bunkers.htm
&lt;script&gt;
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55071422-1', 'auto');
ga('send', 'pageview');
&lt;/script&gt;

<head>
<meta name="description" content="Cold war sites">
<meta name="keywords" content="bunker, cold war, Ace High Station, Ambulance Service Control, Anti Aircraft Operations Room, Bank Operations Centre, Broadcasting Control, Central Government Control, Civil Defence Corps Control, Electricity Supply Control, Fire & Rescue Service Control, Flood Control, Food Supply Control, Fuel Oil Distribution Control, Gas Supply Control, Gun Operations Room, Local authority Control, Police Control, Protected Repeater Station, Railway Control, Regional Fire Control Centre, Regional Seat of Government, RSG, Regional War Room, Rotor, Centimetric Early Warning, CEW, Chain Home, CHL, CHEL, Ground Control Intercept, GCI, Sector Operations Centre, Royal Observer Corps, ROC, Sub Regional Control, Sub Regional HQ, Regional Government HQ, RGHQ, Telecommunications Control, Telephone Exchange, United Kingdom Warning & Monitoring Organisation Control, UKWMO">
<meta name="author" content="Bill Ridgeway">
</head>

Script – Index.htm
&lt;script&gt;
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55071422-1', 'auto');
ga('send', 'pageview');
&lt;/script&gt;

<head>
<meta name="description" content="Preventive maintenance for computers">
<meta name="keywords" content="Backing-up, Backing up, Best tips, Computer Solutions, Configuring Outlook Express, Designing a spreadsheet; Do you depend on your computer working perfectly, Health Check Action Plan, How to do, My computer doesn’t work, Power supply management, Preventive maintenance for computers, Rates, Reformatting a hard disk drive, Remedying spyware & virus threats, Selecting a broadband internet service provider, Terms & conditions of business, Threat prevention ">
<meta name="author" content="Bill Ridgeway">
</head>

Script – Paddock.htm
&lt;script&gt;
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55071422-1', 'auto');
ga('send', 'pageview');
&lt;/script&gt;

<head>
<meta name="description" content="Paddock Information Collection">
<meta name="keywords" content="bunker, Dollis Hill, Paddock, Post Office, Building 11, Cabinet War Room, Churchill, CWR2, Engineering Research Station, Standby Cabinet War Room">
<meta name="author" content="Bill Ridgeway">
</head>
END CODE
on -
www.1001solutions.co.uk
www.1001solutions.co.uk/paddock.htm
www.1001solutions.co.uk/bunkers.htm

Although from what I understand from your previous post this may not all be necessary and I would like to avoid adding code to each file if I can.

The next challenge is to get usage stats for the DOC, PDF, XLS and ZIP file.

Apologies for a long post but you now have everything I know on the matter - but I like a challenge.

Diolch yn fawr

Re: Web site usage statistics

[ Edited ]
Top Contributor
# 8
Top Contributor

I'm really not understanding some of the html code on the pages  bunker.htm or paddock.htm

there are more than one <head></head> section etc and the GA tracking code is not within any of them,

even though it is included at the top of those particular pages.

 

The html code on index.htm looks correct but does not have any GA tracking code

.

Usually the tracking code:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55071422-1', 'auto');
ga('send', 'pageview');
</script>

 

would be installed on every page of the website.

at the bottom of any page with embedded links to files you want to track such as .zip .doc .pdf files etc

Just before the closing </body> tag at the bottom of those pages, add the following code

 

<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'/>

<script type='text/javascript'>
if (typeof jQuery != 'undefined') {
var filetypes = /\.(zip|anf|pdf|doc.*|xls.*|ppt.*|)$/i;
var baseHref = '';
if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');
var hrefRedirect = '';

jQuery('body').on('click', 'a', function(event) {
var el = jQuery(this);
var track = true;
var href = (typeof(el.attr('href')) != 'undefined' ) ? el.attr('href') : '';
var isThisDomain = href.match(document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]);
if (!href.match(/^javascript&colon;/i)) {
var elEv = []; elEv.value=0, elEv.non_i=false;
if (href.match(filetypes)) {
var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
elEv.category = 'download';
elEv.action = 'click-' + extension[0];
elEv.label = href.replace(/ /g,'-');
elEv.loc = baseHref + href;
}
else track = false;

if (track) {
var ret = true;

if((elEv.category == 'download') && (el.attr('target') == undefined || el.attr('target').toLowerCase() != '_blank') ) {
hrefRedirect = elEv.loc;

ga('send','event', elEv.category.toLowerCase(),elEv.action.toLowerCase(),elEv.label.toLowerCase(),elEv.value,{
'nonInteraction': elEv.non_i ,
'hitCallback':gaHitCallbackHandler
});

ret = false;
}
else {
ga('send','event', elEv.category.toLowerCase(),elEv.action.toLowerCase(),elEv.label.toLowerCase(),elEv.value,{
'nonInteraction': elEv.non_i
});
}

return ret;
}
}
});

gaHitCallbackHandler = function() {
window.location.href = hrefRedirect;
}
}
</script>

 

It may then take up to 24-48hrs for data to show up in the Behaviour > Events reports.
This will not track files that ppl access directly via the server. GA does not usually track

that type activity

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Re: Web site usage statistics

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
Bronwyn.

I produced an HTM page which included the (unedited) script you supplied embedded but sorry to report that not only did GA not report access to DOC, PDF, XLS or ZIP files it did not even report the many test access to the HTM file.. Is the script a working example? What may have gone wrong?

Re: Web site usage statistics

Top Contributor
# 10
Top Contributor
Hi Bill.. can you please provide a link to the HTM page that you added the scripts to.
I'd like to be able to have a look at the page in question in my browser i order to debug and see why it may not be working as expected.
Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here