Vimeo tracking in Google Analytics not sending events - google-analytics

I have followed the documentation from Vimeo to track play-events in Google Analytics but no events are being sent.
<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', 'MY-ANALYTICS-ID', 'auto');
ga('send', 'pageview');
</script>
<script type="text/javascript" defer="defer" src="https://extend.vimeocdn.com/ga/MY-VIMEO-ID.js"></script>
The Vimeo iframe is not loaded in a modal or anything. It's just a simple iframe copy pasted from Vimeo embed.
It's tracking normal page views but the Vimeo script is not sending any events. Any ideas?

I found the error myself.In the Vimeo script it basically says something like this:
if (window.dataLayer) {
window.dataLayer.push("", "");
} else if (window.ga) {
window.ga("", "");
} else if(window.gtag) {
window.gtag("", "");
}
So if Google Tag Manager (dataLayer) is installed you cannot track with ga().

I have been trying to track Vimeo in GA and have used several json packages from experts to no avail. so I wonder if that is the problem. Example: https://www.analyticsmania.com/post/google-tag-manager-video-tracking/

Related

Google Analytics Cross Domain Measurment issue with hyperlinks containing #

I am seeing some issues with Google Analytics and the way it inserts the GA id into cross domain measurement links. I can reproduce this both with Google Tag Manager and then also the old school way by just loading the GA script directly. Code here:
<html>
<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-111111111-1', 'test.com');
ga('require', 'displayfeatures');
// Load the cross-domain linker plugin.
ga('require', 'linker');
// Define which domains to autoLink.
ga('linker:autoLink', ['test-domain.net']);
ga('send', 'pageview');
</script>
<body>
<a href='http://test-domain.net/#/test-domain/site.html&clicker=true'>Click me</a>
</body>
</html>
I would expect the output of the url to be:
http://test-domain.net/#/test-domain/site.html?clicker=true&_ga=2.115223111.1566745105.1588030631-1078940747.1588030631
However the result of this is actually
http://test-domain.net/&_ga=2.115223111.1566745105.1588030631-1078940747.1588030631#/test-domain/site.html?clicker=true
Simply removing the hash in the href and the link looks like this.
http://test-domain.net/test-domain/site.html?clicker=true&_ga=2.81275223.1566745105.1588030631-1078940747.1588030631
This is easy to replicate in a JSFiddle as seen here. https://jsfiddle.net/andrewmacnaughton/xa3yp876/1/
I do realize that what I have below is possibly an antiquated version of using GA Cross Domain, however i receive exactly the same via GTM.
Does anyone have any ideas here. We are stalled on putting this into production as we are convinced that 1: The URL is ugly, 2 and most importantly: Not convinced that GA will track things correctly as it looks like an invalid URL.
I managed to solve this if anyone ends up here.
Instead of allowing Google to auto append the GA code to the link, i had to manually decorate it.
<body>
<a id='test' href='http://test-domain.net/test-sss/#/site.html?click=true'>Click me</a>
<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-111111111-1', 'auto');
ga('require', 'displayfeatures');
// Load the cross-domain linker plugin.
ga('require', 'linker');
// Define which domains to autoLink.
// Adds click handler that decorates `destinationLink`.
var destinationLink = document.getElementById('test')
destinationLink.addEventListener('click', function () {
ga(function (tracker) {
var linkerParam = tracker.get('linkerParam');
var uri = buildUrl(destinationLink.getAttribute('href'), linkerParam)
destinationLink.setAttribute('href',uri)
});
});
function buildUrl(baseURL,linkerParam){
return baseURL.indexOf('?')>-1 ? baseURL + '&' + linkerParam : baseURL + '?' + linkerParam
}
</script>
</body>

Same web property ID is tracked twice

I'm using the following code in my page, in order to have Google Analytics and Tag Manager.
<script type="text/javascript">
(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-xxxxx', 'auto');
ga("require", "displayfeatures");
ga('send', 'pageview');
</script>
and
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxx"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-xxxxxx');
</script>
So I'm getting warning "Same web property ID is tracked twice" in Google Tag Assistant.
Is there anyway I can fix this warning?
Actually you have two Google Analytics codes on your page and both are sending 'pageview' hits to Google Analytics. The first one is somewhat older analytics.js snippet and the second is a little bit newer gtag.js snippet. None of them has anything to do with Google Tag Manager.
Consider using just one, either analytics.js or gtag.js. Note that if you'll also install GTM and set up pageview tracking in GTM you'll get the same issue again because GTM will duplicate the existing analytics snippet functionality.

google optimize - installation issue

Is there a way to specify what datalayer Google Optimize will use?
I have two datalayers and i would like to specify which one will be used for google optimize. Google Optimize by default is using my first one that is not array object and that's why the installation fails. GA tag is visible in tag assistant, but google optimize tag is not. If i change first one to be javascript array object both tags are loaded properly.
Please take a look at code snippet below.
P.S. Google optimize code snippet is added directly to page, not via GTM.
Thank you in advance!
<head>
<script type="text/javascript">
var dataLayer = {}
</script>
<script type="text/javascript">
var googleAnalyticsDataLayer = []
</script>
<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', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-XXX', 'auto');
ga('require', 'GTM-XXX');
ga('send', 'pageview');
</script>
</head>

Google analytics shows no hit on mobile.aspx of sitecore website

I am just testing google analytics on my sitecore website. After setting up everything i used below code to set on my main.aspx page.
<!-- Google Tag Manager -->
<noscript>
<iframe src="//www.googletagmanager.com/ns.html?id=GTM-TVSCV2" height="0" width="0" style="display: none; visibility: hidden"></iframe>
</noscript>
<script>
(function(w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js'
});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src =
'//www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-TVSCV2');
</script>
<!-- End Google Tag Manager -->
Problem is that 'hits' on website working well with in case of 'main.aspx' but not working once I am going for 'mobile.aspx'. Hit counts remains '0' in case of mobile device.
Please suggest.

Using Google Analytics to track clicks

Very simple scenario: I simply wish to track, using google analytics, every instance that a visitor of my site clicks on a link to an external website. I've done this using event tracking to the best of my understanding, but when I then click on the link, I don't see any tracking in the google analytics report.
I'm wondering if:
(a) there is something wrong with my code;
(b) I'm not looking in the right place in my google analytics account;
(c) both
Below is my entire page in its entirety, subsitituting 111111111 for the actual account id:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<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-1111111111-1', 'mysite.com');
ga('send', 'pageview');
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1111111111-1']);
_gaq.push(['_trackPageview']);
(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);
})();
</script> <a target="_blank" onClick="_gaq.push(['_trackEvent', 'Links', 'Click', 'CNN']);"
href="http://www.cnn.com">CNN</a>
<br/>
</body>
</html>
There are few things wrong with your code:
Analytics version
You're mixing up the old ga.js and the newer analytics.js
Just use only the newer analytics.js
Race condition
You're tracking the event onClick, but at this point, the browser's already leaving the page and the request may not go through.
Basically, opening cnn.com and submitting the event are competing in the browser window.
Use a hit callback, and set window.location.href, and you'll be fine:
ga('send', 'event', {
'eventCategory': 'Links',
'eventAction': 'Click',
'hitCallback': function() {
window.location.href = "http://www.cnn.com";
}
});
This way, the browser will wait for the event to be submitted, and then access cnn.com.

Resources