-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
Describe the bug
Full explanation here
#86
Problem
Bounce rates are too high in GA dashboard due to duplicate page view events on page load.
Fix
Provide the option to utilise the 'send_page_view' param to disable the first request.
https://developers.google.com/analytics/devguides/collection/gtagjs/pages
Code Changes Required
/services/google-analytics.js
Lines 23-46
exports.initializeGoogleAnalytics = function (options) {
if (!window.gatsbyPluginGDPRCookiesGoogleAnalyticsInitialized && getCookie(options.cookieName) === "true" && validGATrackingId(options)) {
window.dataLayer = window.dataLayer || [];
window.gtag = function () {
window.dataLayer.push(arguments);
};
window.gtag('js', new Date());
var gaAnonymize = options.anonymize;
var gaAllowAdFeatures = options.allowAdFeatures;
var gaPageViewOnLoad = options.sendPageViewOnLoad
gaAnonymize = gaAnonymize !== undefined ? gaAnonymize : true;
gaAllowAdFeatures = gaAllowAdFeatures !== undefined ? gaAllowAdFeatures : true;
gaPageViewOnLoad = gaPageViewOnLoad !== undefined ? gaPageViewOnLoad : true;
window.gtag('config', options.trackingId, {
'anonymize_ip': gaAnonymize,
'allow_google_signals': gaAllowAdFeatures,
'send_page_view': gaPageViewOnLoad
});
window.gatsbyPluginGDPRCookiesGoogleAnalyticsInitialized = true;
}
};
default-options.js
line 7-12
googleAnalytics: {
cookieName: "gatsby-gdpr-google-analytics",
anonymize: true,
allowAdFeatures: false,
sendPageViewOnLoad: false
},
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels