In my react app I used react-gtm-module
. and I have GTM ID only.
I put the below code in each page router ponent
import TagManager from 'react-gtm-module';
ponentDidMount(){
const tagManagerArgs = {
dataLayer: {
page: '/pagepath'
},
gtmId: 'GTM-XXXXXX',
}
TagManager.initialize(tagManagerArgs)
}
I just put the above code in each route ponent. By using the above code, in google analytics sometimes the path shows and sometimes not showing in Active Page
.
Is it only code I have to put in my code to achieve google analytics track pages or I have to add more else? If yes then exactly what I have to add and where to add?
Definitely, I miss something in my code. But what exactly?
In my react app I used react-gtm-module
. and I have GTM ID only.
I put the below code in each page router ponent
import TagManager from 'react-gtm-module';
ponentDidMount(){
const tagManagerArgs = {
dataLayer: {
page: '/pagepath'
},
gtmId: 'GTM-XXXXXX',
}
TagManager.initialize(tagManagerArgs)
}
I just put the above code in each route ponent. By using the above code, in google analytics sometimes the path shows and sometimes not showing in Active Page
.
Is it only code I have to put in my code to achieve google analytics track pages or I have to add more else? If yes then exactly what I have to add and where to add?
Definitely, I miss something in my code. But what exactly?
Share Improve this question asked Mar 27, 2021 at 8:40 Yuvraj ChaudhariYuvraj Chaudhari 2412 gold badges5 silver badges10 bronze badges 1- 1 Is it necessary to send the page path? Doesn't GTM always automatically send that info? – Alex von Brandenfels Commented Sep 23, 2021 at 18:26
1 Answer
Reset to default 13Initialise with just the id in each app, not each page
TagManager.initialize({
gtmId: gtm_id,
});
and then in each page,
TagManager.dataLayer({
dataLayer: {
event: 'pageview',
pagePath: 'page-path-here',
pageTitle: 'page-title-here',
},
});