4K members online now
4K members online now
Everything you need to know about setting up Optimize including creating your account and container, linking to Google Analytics and how to tag your site.
Guide Me

Activation Events not triggering experiment

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭



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)


1 Expert replyverified_user

Activation Events not triggering experiment

Google Employee
# 2
Google Employee


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):