Has anyone been able to include downloads within a custom report in Google analytics? I know I can get general/all events, but I just want downloads.
Thanks
If you are asking to track the downloads then you can add _trackEvent method in to the link that you want to track, like
Click <a onclick="_gaq.push(['_trackEvent', 'Downloads', 'Demo', this.href]);" href="downloads/google_dynamic_map.zip">here</a> to download with demo.
Above code is from my working site and I'm able to track download of that file.
To view the report you can select the Contents->Events menu from the left nav bar of your google analytics page.
In my link Downloads is the Event Category and Demo is the Event Action and this.href is my Event Label which gives me the url of the file.
I've also created a custom report only to track Downloads event category from Google's custom report option and can track it from that custom report, filtered by Downloads.
Screenshot of Custom Report settings
Screenshot of standard report and viewing from content menu
Useful links here: Link One and Link Two and Event Tracking Guide.
Update: Also remember it'll take some time after you setup all of those things to track and see the result.
Google Analytics on Steroids offers a great _gasTrackDownloads hook in their API if you don't already have the tracking code in place per #Sheikh's more accurate Custom Report answer above.
Code Example:
<script type="text/javascript">
var _gas = _gas || []; // _gas instead of _gaq
_gas.push(['_setAccount', 'UA-YYYYYY-Y']); // REPLACE WITH YOUR GA NUMBER
_gas.push(['_setDomainName', '.mydomain.com']); // REPLACE WITH YOUR DOMAIN
_gas.push(['_trackPageview']);
_gas.push(['_gasTrackForms']);
_gas.push(['_gasTrackOutboundLinks']);
_gas.push(['_gasTrackMaxScroll']);
_gas.push(['_gasTrackDownloads']); // track downloads
_gas.push(['_gasTrackYoutube', {force: true}]);
_gas.push(['_gasTrackVimeo', {force: true}]);
_gas.push(['_gasTrackMailto']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = '//cdnjs.cloudflare.com/ajax/libs/gas/1.10.1/gas.min.js'; // new url
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
Link: Google Analytics on Steroids
Related
In my website we have a banner which on clicking directs the user to our client's website. In order to track the number of people clicking the banner we decided to make use of the google analytics events component. I added the JS provided by them just below my Google analytics script.
var captureOutboundLink = function(url) { ga('send', 'event', 'outbound', 'click', url, { 'transport': 'beacon', 'hitCallback': function(){document.location = url;} }); }
Then in the place of the banner I called the function
<a href="https://example.com/pg/" onclick="return captureOutboundLink('https://example.com/pg/');">
<img src="https://www.moreexample.com/admin/banner/mascot.jpg" alt="macott2022" title="macott2022" class="img-res innerbann" />
But the google analytics events tab is still not tracking. I tried clicking the Banner few times but it shows no signs of activity. Does it take time to reflect ?
yes, events report might need some time to process the data. you can use "events" section of real-time report instead.
moreover you might use Tag assistant or other GA debugging tool to make sure that your event data being sent.
I would like to track beforeunload event on SPA website, as I want to send data via GTM to datalayer. I want to track video watch time (HTML5 player) and send the data right before a user leaves the current page either to another one on the same website or completely different.
Is there a way to have this done via GTM custom HTML?
Assuming that you have a way to capture the video time in a variable, you can send that information to Google Analytics using an event listener for the beforeunload event. I’m doing that on one of my webpages to get an idea of how long users have the page open.
Here’s the code I’m using:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
// Disable tracking if the opt-out cookie exists
if (document.cookie.indexOf("ga-disable-GA_MEASUREMENT_ID=true") > -1) {
window["ga-disable-GA_MEASUREMENT_ID"] = true;
}
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag("js", new Date());
gtag("config", "GA_MEASUREMENT_ID", { "anonymize_ip": true, "cookie_flags": "SameSite=None;Secure" });
</script>
<script>
window.addEventListener("beforeunload", function (e) {
gtag('event', 'Time_Spent', {
'event_category': 'Time_on_page',
'event_label': e.timeStamp.toString,
'value': 1,
'transport_type': 'beacon'
});
delete e.returnValue;
});
</script>
The first section is in the head and the second section is at the end of the body.
I put the event.timeStamp value in the event_label; you could put your video time, formatted however you like into that field as well.
I’m not sure I need the optional value field, but I have it.
The transport_type beacon tells Google to transmit the data asynchronously when the User Agent has an opportunity to do so, without delaying unload or the next navigation.
To see how long people have been spending with my page open, I go to:
Google Analytics -> Behavior -> Events -> Overview
I click on the event category (Time_on_page in my case), and then click on Event Label to get a listing of all of the values.
I'm trying to migrate from Google old Analytics to Universal Analytics. I have code below and from universal - developers guide I couldn't find solution.
Inside my analytics code I had these lines. Part 1:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-123456-1']);
_gaq.push(['_trackPageview','/tools/one');
_gaq.push(['_setCustomVar', 1, 'name', 'michael', 1]);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
Also inside my some other script I have this code snippet. Part 2:
if (typeof _gaq !== "undefined" && _gaq !== null) {
_gaq.push(['_trackPageview', '/dosomework']);
}
How can I convert "gaq.push"s inside 2 parts and add to my universal analytics code ?
Unfortunately, migrating to analytics.js isn't as simple as just changing the code syntax.
Firstly you should know that Universal Analytics is currently in open beta phase. Currently google does not offer a way to "upgrade" or "convert" an existing web property to take advantage of universal analytics (analytics.js) tracking. You will need to setup a new web property (or new account) and check the "universal analytics" radio button.
Google currently recommends setting up analytics.js code in addition to your current ga.js code. Once you are happy that the base data is lining up between the two, you can either keep both versions on your page or decide on a date to remove the old ga.js code. The historical data in your old profile will still be there but it won't be tied to the new web property. I don't know if Google will eventually offer an "upgrade" or "convert" feature for existing ga.js based web properties; so far I have not seen any news on if/when they will offer this.
Moving on to Universal Analytics (analytics.js) code ...
Universal Analytics does not use the .push syntax. Instead, it has a function ga() that requires arguments to be passed to it. The first argument is the "command" argument, and the additional arguments are for passing additional settings, values, etc. based on the command.
setting the GA account is now done with the 'create' command
tracking a page view is now done with with the 'send' command
setting a custom variable* is now done as either an argument in the 'send' command (for only popping it on that 'send' command), or with the 'set' command (for setting it to be popped with all 'send' commands executed on the page)..but about this...
Custom Variables no longer exist
Well they do, but how they are implemented is different. Universal Analytics offers custom dimensions and metrics. Custom Variables are mostly what Custom Dimensions now are. The main difference is that setting things like the name and scope of the variable is now done within the GA interface instead of as an argument to the function. Also, you get more than 5 to work with now. To set this up, click on the web property you created, and you should see tabs
Profiles Tracking ..Custom Definitions
Click on the Custom Definitions tab to setup your custom dimensions and metrics there.
Now on to the page code
This is what the "equivalent" of the code you posted would look like:
First snippet:
<!-- Google Analytics -->
<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-123456-1');
ga('send', 'pageview', '/tools/one');
ga('set', 'dimension1', 'michael');
</script>
<!-- End Google Analytics -->
note: as mentioned above, you would set the name and scope of the dimension within the interface. 'dimension1' should be changed to whatever dimension# you created.
Second snippet:
if (typeof ga == 'function') {
ga('send', 'pageview', '/dosomework');
}
sidenote: Not really related to your question, but in your code you first send a page view and then set the custom variable. In case you didn't know, if you set the custom variable (_setCustomVar) after the page view (_trackPageview), your custom variable will not be sent with that page view (the '/tools/one' hit). It will (assuming your 2nd snippet gets popped later on) be sent along with that 2nd page view (the '/dosomework' one). Not sure why you would have two separate pageviews or if you knew about that order of operations thing but if you're happy with how things currently look in the reports..well the analytics.js version will behave the same way.
How do i get google analytics to work
I've put it in site/settings - tracking code.
I made a google analytics account but it says 0 visited
Hope you guys can help
Best Regards
It takes one day before you will see the result in Google Analytics. It is not real time... If you placed the tracking code on your website you should be good to go.
Place the following script immediatly after your <body> tag.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<<Your UA-000909 ID>>']);
_gaq.push(['_trackPageview']);
</script>
Place the following script immediately before your </body> tag.
<script type="text/javascript">
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
Between the scripts your content should be. This gives the best page load time.
You can test whether Google Analytics is configured correctly immediately after setup by utilizing the Google Analytics realtime view. In one browser tab visit your website, in another tab have Google Analytics open, with the real time tab selected (it can be found on the left hand side of the Google Analytics user interface under the reporting tab).
To install, grab your tracking code (it sounds like you've already done this) and paste before the closing tag.
You can also test whether you've configured Google Analytics correctly by selecting admin, then tracking info, then tracking code. If configured correctly, you should see the Status as "Status: Receiving Data".
Google Analytics is driving my crazy.
I have an app in the app store. I'd like to sent an email linking direct to my app's page in the app store, BUT i'd like to track the clicks.
So far, i have a link like
www.mypage.com/promoletter/
That location contains an index.php file wich does a 302 redirect to my own site as follows:
header("Location: http://www.mypage.com/index.php?page=App_Store
&utm_source=promoletter&utm_medium=email&utm_campaign=v1-promoletter");
I do it this way with 2 redirect because
the url looks nicer and
I can still edit the utm variables after the newsletter has been send
Now, through my index.php page, a html page is created which does an other 302 redirect to
http://itunes.apple.com/ie/app/MY-APP/id-SO-AND-SO?ls=1&mt=8
also using the php header function as above.
Now, everything works great, but of course it's not being recorded in Analytics (hence the question :) ). Writing this, I realize this is because the ga.js file is never loaded because you cannot have any output before the php header function.
How to solve?
Simple code without timeout is:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = false;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
_gaq.push(function(){
window.location.replace("http://itunes.apple.com/ie/app/MY-APP/id-SO-AND-SO?ls=1&mt=8");
});
</script>
There is no need to wait, just setup ga.async = false; and redirect work faster, with little delay.
The best way to solve this is to use a javascript redirect. Send out a html page with the ga.js and a script tag:
...
<script type="text/javascript" src="ga.js"></script>
<script type="text/javascript">
window.location.href = "http://itunes.apple.com/ie/app/MY-APP/id-SO-AND-SO?ls=1&mt=8http://itunes.apple.com/ie/app/MY-APP/id-SO-AND-SO?ls=1&mt=8"
</script>
...
Or to make sure the ga.js is loaded:
...
<script type="text/javascript" src="ga.js"></script>
<script type="text/javascript">
setTimeout('window.location.href = "http://itunes.apple.com/ie/app/MY-APP/id-SO-AND-SO?ls=1&mt=8http://itunes.apple.com/ie/app/MY-APP/id-SO-AND-SO?ls=1&mt=8"',500)
</script>
...
I'm not sure if it's possible to "spoof" the ga pixel request. You might as well need cookies that are not available for you. But else you might be able to fake a ga pixel from your backend to track the correct values.
The javascript redirect might though be a bit more simple :)
Thanks Ragnar,
You pointed me in the right direction and I've learned a lot since posting my question.
Maybe somebody else is interested in my actual solution or somebody has a better way.
I've solved my problem using 3 redirects (I don't see another way unfortunately).
First, I've got a link like:
www.mypage.com/promoletter/
This than redirects to (php header function):
header("Location:
http://www.mypage.com/index.php?page=processGAVars&nextPage=App_Store
&utm_source=promoletter&utm_medium=email&utm_campaign=v1-promoletter");
The constructed page is processing the Google Analytics variables and once again redirects to another page (nextPage=App_Store) this time using javascript or meta refresh when javascript is disabled.
You could redirect straight to the App Store, but than the user is left with a URL in it's address bar containing your GA variables (apparently only on iPhone/iPad, see below).
There is a short delay before redirection so GA gets a change to do it's job (race condition).
$url = "http://www.mypage.com/index.php?page=".$_GET['nextPage'];
<noscript>
<meta http-equiv="refresh" content="1; url=<?php echo $url;?>" />
</noscript>
<script type="text/javascript">
function redirect() {
window.location.replace("<?php echo $url;?>");
}
</script>
<body onload="setTimeout('redirect()', 500)">
The last page does the actual redirect to the App Store again using javascript or meta refresh just like above only this time without any delays.
So far, in the browsers I have tested (firefox with and without javascript, chrome, safari and on iPhone/iPad safari and terra) there is a short delay and the user can see the redirect. However, this redirects doesn't show up in the users history and pressing the back button once returns the te previous page.
On a computer the user, gets the itunes.apple.com page. On an IOS device, the App Store app is launched and the browser displays the page the user left.
I have found that on an iDevice, including the GA javascript in the page that does the actual redirecting to the iTunes page, blocks the process of going back to the originating page (e.g. stackoverflow.com). The user is than presented the (blank) redirection page.
See it in action?
http://hd-apps.com/links/stackoverflow/