Setting setSiteSpeedSampleRate in gtag.js - google-analytics

I want to increase the Sample Rate for Page Timings from 1% to 10% in google analytics.
We are using Global site tag (gtag.js) for adding GA to our site.
Following is current config:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-123456-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123456-1');
</script>
As per the doc, the following will capture the user load time, but it won't increase the sampling rate.
// Feature detects Navigation Timing API support.
if (window.performance) {
// Gets the number of milliseconds since page load
// (and rounds the result since the value must be an integer).
var timeSincePageLoad = Math.round(performance.now());
// Sends the timing event to Google Analytics.
gtag('event', 'timing_complete', {
'name': 'load',
'value': timeSincePageLoad,
'event_category': 'JS Dependencies'
});
}

This was solved by setting, gtag('config', 'UA-XXXX-X',{'site_speed_sample_rate': 100})

Related

Very low bounce rate in google analytic

I know a low bounce rate is due to double tracking but I don't find the problem on that website
The tracking code is this one:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-12345678-9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-12345678-9', {
'custom_map': {'dimension1': 'Appli'}
} );
gtag('set', {'user_id': '1'});
gtag('event', 'page_web', {'Appli': 'non'});
</script>
I don't see how to remove something...
The problem is due to the fact that you are setting an event on page load. By default the gtag tag will first create a pageview hit that is sent to Google Analytics.
Then your gtag('event', 'page_web', {'Appli': 'non'}); call is fired. Because this is an interaction event, it will count as a user interaction, and thus the bounce rate for the page will be zero (a bounce is recorded if there are no interaction hits after a pageview hit on a single page).
I'm not sure what you are using the event for, but if it is something that is recording automatically, then I would suggest configuring it as a non-interaction event hit:
gtag('event', 'page_web', {'Appli': 'non', 'non_interaction': true});

Why isn't gtag sending ad conversion tracking?

I'm using gtag.js to track Google Ads.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-abc123"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-abc123');
</script>
This is the code to trigger my Google Ads Conversion Tracking pixel:
var callback = function () {
if (typeof(url) != 'undefined') {
window.location = url;
}
};
gtag('event', 'conversion', {
'send_to': 'AW-abc123/12345',
'event_callback': callback
});
When I load my page with a fresh cache, I can see my conversion pixel being fired:
However, after a page reload, the conversion no longer fires:
What is causing the conversion tag to stop firing?
Why do you think that tag doesn't fire? Blue color in Tag Assistant indicates non-standard implementation etc. Try to click on your tag in Tag Assistant and see details.

To get event corresponding to page load time in Google Analytics

I want to track page load time using google analytics. I have a single page application . In order to track i added the given script inside head tag . And in order to get page load time , i added the second script just before the body tag but unfortunately i am not able to find any event in Google Analytics corresponding to this . It seems like this gtag() is not executing somehow. Can someone please help out. Also where do we see event_value in Google analytics. I am able to find event_category and event_action by going into RealTime->Events but i can't find any event_value there.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-X');
</script>
<script>
if(window.performance){
// Gets the number of milliseconds since page load
// (and rounds the result since the value must be an integer).
var timeSincePageLoad = Math.round(performance.now());
// Sends the timing event to Google Analytics.
gtag('event', 'timing_complete', {
'name': 'load',
'event_value': timeSincePageLoad,
'event_category': 'Home page loading time'
});
}
</script>
According to documentation it should be value, not event_value
gtag('event', 'timing_complete', {
'name': 'load',
'value': timeSincePageLoad,
'event_category': 'Home page loading time'
});

Dimension only tracks one Customer

I'm stumped. We only get one fruit type showing up in analytics when there should be multiple showing up for pageview tracking per fruit type;
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{analyticsAccount}}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{analyticsAccount}}', {
'custom_map': {
'dimension1': 'fruitType',
'dimension2': 'userId',
}
});
gtag('set', 'fruitType', {{fruitType}});
gtag('set', 'userId', '{{userId}}');
</script>
<!-- end global site tag -->
For some reason, it's only showing one fruit type when looking at either custom or standard reports and we know our system is sending in many types of fruit.
Unfortunately I don't have a public page I can share.

Global Site Tag Migration - Sample rate not working for pageviews

I've migrated from Universal to Global Site Tag. I've got sample_rate:50. It's not working for Pageviews.
Now: pageviews = 100. Expected: pageviews = 50.
Can you please show me an example that works?
https://jsfiddle.net/5owj671h/
<script async src="https://www.googletagmanager.com/gtag/js?id=<?
=$gaTrackingCode?>"></script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag('js', new Date());
gtag('config', '<?= $gaTrackingCode ?>', {
'custom_map': {'dimension3': hasAdBlock},
'sample_rate': 50
});
gtag('event', 'page_view', { 'send_to': '<?= $gaTrackingCode ?>',
'sample_rate': 50 });
</script>
The gtag scripts sends the pageviews automatically so when I stopped sending pageviews, it worked.
sampleRate works with users, not page views. And I guess sample_rate is a wrong name.

Resources