google-optimize

Google optimize targeting when query param is NOT present


I would like to target only the page which does not have specific query param. Value does not matter, what matter is that the params is not in the url, and only then run the experiment.

I tried to use matches regex but does not work:

Regex I use: ^[a-zA-Z]+


Solution

  • It can be done using custom JS func variable like this

    function () {
       return window.location.search.includes('nameOfYourParam')
    }