AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

1.8K members online now
1.8K members online now
Discover how to select who is eligible to be in your experiment, and when they’re served experiment variations.
Guide Me

Activate an experiment with a custom event: Possible with GTM?

Follower ✭ ✭ ☆
# 1
Follower ✭ ✭ ☆

Hey there,
I am receiving an error message when I am setting up my experiment: "Page modified after initial load: The content of this page has been modified after the page was initially loaded. Make sure your changes are rendering correctly by using preview mode".


Since the changes are not visible in preview mode I have a problem to which "Activation Events" ( should be the solution.


Since I have limited access to a developer I am wondering if I can create/fire the activiation event via GTM.


Thanks a lot for your help.





1 Expert replyverified_user

Activate an experiment with a custom event: Possible with GTM?

Google Employee
# 2
Google Employee

If you can use a custom HTML tag in GTM, you should be able to do it, but consulting with a developer would be ideal, since this will involve code.


You are supposed to send activation events after you page has changed (by javascript), but since it will be hard for you to figure out when this happens, you could perhaps use some code that will work on all modern browsers and re-active Optimize every time that the page content changes.


The code to add in the HTML code is below (but make sure to test it).


if (MutationObserver) {
  new MutationObserver(function(){
    setTimeout(function() {
      dataLayer.push({'event': 'optimize.activate'});
    }, 0);
  }).observe(document.body, {subtree: true, attributes: true, characterData: true});


These should work with modern browsers ( - in case you have any visitors with old browsers will simply not be included in the experiment.

An alternative would be to try out some of the default events for the web that GTM uses (instead of optimize.activate).


Perhaps gtm.load may work in your case (depends on when your page gets modified).


For more details see the bottom of: