Exclude a Script Applied Via Script Manager from Executing on a Page


community tips scripts banner

Have you added a script via script manager but would like to prevent it from firing on specific pages on the domain? Now you can!

This script works by looking for a word or string of characters in the URL of a page. If the URL contains the specified characters the script applied via script manager will not fire.

:rotating_light: WARNING: YOU ARE ENTERING DEVELOPER TERRITORY :rotating_light:
This is not an official Unbounce feature. This functionality is based entirely on third party code, and has only been tested in limited applications. Since this isn’t a supported Unbounce feature, our support team will be unable to assist if things go awry. So if you are not comfortable with HTML, Javascript and CSS, please consider consulting an experienced developer.

Step 1.

When adding a script via Script Manager you’ll need to wrap it in the function found here: https://gist.github.com/RobertCam/19422998c8c27f4affd1b1cda2eb3b4a

Make sure that your code is located in the correct place in the script:

 if (document.location.href.indexOf(excludeFromSM) === -1){ 
    // Your code goes here

Step 2

Choose the word or characters to look for in the URL. This is the equivalent of saying “if the URL of a page contains _____ do not fire the code”.

The value of the variable var excludeFromSM is what the script looks for to prevent the code from executing.

Want to take your Unbounce landing pages + Convertables™ to the next level?
:spinbounce: Check out the Ultimate List of Unbounce Tips, Scripts & Hacks