wide-cartoon-5349
10/04/2024, 5:56 PMorange-terabyte-33302
10/04/2024, 5:56 PMorange-terabyte-33302
10/04/2024, 5:56 PMjavascript window.growthbook = new GrowthBook({ // ...other config options... trackingCallback: (experiment, result) => { // Send data to the DataLayer window.dataLayer.push({ 'event': 'experiment_viewed', 'experiment_id': experiment.key, 'variation_id': result.variationId }); } });
This code will send an event to the DataLayer whenever a user views an experiment. The event will include the experiment ID and the variation ID. You can then use Google Tag Manager to forward this event to your analytics tool of choice. For more information, you can refer to the [GrowthBook documentation](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook#tracking-via-datalayer-and-gtm) and the [forum conversation](https://linen.growthbook.io/t/16933284/struggling-with-growth-2-9s-new-html-script-tag-sdk-and-goog) where this issue was discussed.