Search code examples
asynchronousgoogle-tag-managergoogle-optimize

How can I make Google Optimize variant to wait until everything is loaded?


I got a Google Tag manager - Google Optimize environment in my React APP. When I start my experiment on google Optimize the variant is applied but as soon as the translations are applied everything goes back to the regular page.

This is because of the asynchronous process of i18n,

The page loads The variant is applied The internationalization is applied The variant changes are discarded

Is there any way to ensure that the variant won't be changed?


Solution

  • If possible you can choose to add an event in the code to trigger the optimize experiment after the internationalization occurs something like the below, then in Google Optimize choose load experiment on custom event.

    dataLayer.push({'event': 'optimize.activate'});