Add an option called fireGtmOnFirstPageLoad
in gtm package for fixing the "Duplicate tracking of the first page" when GA4 and GTM both tracks the page analytics
#37057
Unanswered
som-matrix
asked this question in
Ideas / Feature Requests
Replies: 1 comment
-
@LekoArts please check the above discussion |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello folks, wanted to start a discussion on how we can prevent the duplicate tracking of the first page view when we are using both GA4 and GTM for our application analytics.
Goal : First page view should be tracked either by GA4 or GTM , so in our case we can control GTM package to stop sending the first page view when gatsby detects that it is the first page i.e (prevLocation === null)
Reference : In here -> https://www.bounteous.com/insights/2018/03/30/single-page-applications-google-analytics , please check the Duplicate Tracking of the First Page section.
How to achieve this feature
So first we will go to
packages/gatsby-plugin-google-tagmanager
and ingatsby-node.js
we will add a option calledfireGtmOnFirstPageLoad
which will betrue
by default.then in we need to used this option in
onRouteUpdate
method ingatsby-browser.js
.Let's discuss the above logic with some metrics
for eg: condition = isFirstPage && !pluginOptions.fireGtmOnFirstPageLoad
// fireGtmOnFirstPageLoad = true
// User visit gatsbyjs.com: (prevLocation will be blank): condition = false , so fireGtm = true
// User goes to /support : (prevLocation will not be null): condition = false, so fireGtm = true
// fireGtmOnFirstPageLoad = false
// User visit gatsbyjs.com: (prevLocation will be blank): condition = true, fireGtm = false
// User clicks on /support: (prevLocation will not be null): condition = false , fireGtm = true
Beta Was this translation helpful? Give feedback.
All reactions