Activation Events not triggering experiment[ Edited ]
May - last edited May
We're building Optimize into our React front-end app and are experiencing some issues with actually getting experiments triggered. We're also using Tag Manager.
We've tried the following suggestions:
1. Load Optimize using the amended GA Tracking script before GTM tracking script, as suggested by Google
2. Load Optimize using Tag Manager and remove all GA tracking, also suggested by Google
On every route change, we push two events into the dataLayer*:
1. A virtual pageview event for Analytics tag
2. Activation event as Google's guide suggested
* Disclaimer: Only after verifying that window.dataLayer exists
In the Optimize container we've set-up two mock experiment 50/50 split, targeting traffic on URL path containing "test" with the difference between the experiments:
1. Triggered on Activation Event, URL containing test
1. Triggered on Pageload, URL containing test
Now we've tested both these set-ups, but Google Optimize still won't activate the experiments even though the conditions are met. We've used Analytics Debugger to see what data is sent back to the tracker, and everything seems fine. In the GTM implementation we've checked that GTM is able to pull Page URL dataLayer variable's correctly, which it does.
Why won't they activate? Are we missing something here? Worth noting is that we're testing this on a local development environment, does Google Optimize require the front-end to be hosted on a public web server to function correctly? (not needed for GTM atleast, so shouldn't make a difference)
Activation Events not triggering experiment
Google Optimize doesn't require a public web server to function correctly so this shouldn't be your problem.
Could you check the following:
- Ensure that you have enabled custom activation for your experiment (in the targeting section). See image at: https://support.google.com/360suite/optimize/answer/7008840?hl=en
- Could it be that you are doing the activation a bit too early (before React has applied the route change effects on the DOM)? Consider sending the event within a setTimeout(0).
You may also use mutation observers to troubleshoot (i.e. to check that there is no other problem with the setup), or even use them as your activation mechanism (they are quite well supported these days).
See this page as an example http://webopttest.webutu.com/examples/react.html (related code is at the bottom of page source):