worried-planet-2191
03/08/2023, 4:02 PMfresh-football-47124
fresh-football-47124
fresh-football-47124
fresh-football-47124
fresh-football-47124
busy-air-96466
03/08/2023, 7:59 PMhappy-autumn-40938
03/08/2023, 10:18 PMwindow.gtag to see whether it's actually (eventually) defined.happy-autumn-40938
03/08/2023, 10:31 PMbusy-air-96466
03/10/2023, 2:05 PMbusy-air-96466
03/10/2023, 2:21 PMbusy-air-96466
03/10/2023, 2:41 PMwindow.dataLayer.push({
event: 'login',
userId,
});fresh-football-47124
busy-air-96466
03/13/2023, 4:11 PMuseFeatureIsOn('new-main-panel');
iin a component.
const growthbook = new GrowthBook({
apiHost: '<http://localhost:4100>',
clientKey: 'sdk-xxxxxx',
enableDevMode: true,
trackingCallback: (experiment, result) => {
console.log('Viewed Experiment', {
experimentId: experiment.key,
variationId: result.key,
});
// track using GA4
window.dataLayer.push({
event: 'experiment_viewed',
event_category: 'experiment',
experiment_id: experiment.key,
variation_id: result.variationId,
});
},
});
1. I may have missed something, but gtag doesn’t seem to exist if you follow the latest GTM instructions. Instead, you have to use window.dataLayer.push to send the tracking event to GA4. Maybe that should be in the docs?
2. Is there a way to call trackingCallback again in a session - if the user logs out, and a different user logs in?busy-air-96466
03/13/2023, 4:56 PMhappy-autumn-40938
03/13/2023, 5:41 PMIn some situations,may never become defined. You can use your browser's developer tools / JavaScript console to confirm this by typinggtag(). If undefined, you may need to manually define it — either on your page or in a GTM custom HTML tag — using JavaScript. For example:window.tag
Copy codewindow.gtag = window.gtag || function() { dataLayer.push(arguments); };
busy-air-96466
03/13/2023, 6:37 PMalert-leather-41230
03/14/2023, 2:56 PMhappy-autumn-40938
03/14/2023, 3:16 PMalert-leather-41230
03/14/2023, 3:18 PMhappy-autumn-40938
03/14/2023, 3:20 PM