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

Optimize
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
star_border
Reply

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" (https://support.google.com/360suite/optimize/answer/7008840#activate-on-custom-event) 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.

 

Regards,

Jochen

 

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

 

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

 

These should work with modern browsers (https://caniuse.com/#feat=mutationobserver) - 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:

https://support.google.com/tagmanager/answer/6103657?hl=en