These selectors can use an entire URL or just a small section of it as a key to include or exclude a specific page. The examples below use http://www.intilery.com/about-us
|Selector||What it refers to||Will include/exclude|
|window[‘location’][‘href’]||http://www.intilery.com/about-us||This exact URL|
|window[‘location’][‘protocol’]||http:||Any page with this protocol|
|window[‘location’][‘hostname’]||www.intilery.com||Every page under this domain|
|window[‘location’][‘pathname’]||/about-us||Every page with these parameters|
Excluding/Including a single page
In this example we want to exclude a custom module from the About Us section of the Intilery website so we will use the selector than uses pathname from above:
window[‘location’][‘pathname’] != “/about-us”
In this example the != operator specifies that if the parameters after the URL match then the page will be exclude from the custom module. To specify that it should only appear on a page which has these parameters replace != with == like so:
window[‘location’][‘pathname’] == “/about-us”
Excluding/Including multiple pages
For multiple pages your selector will not be much different from doing it with a single page, you simply write two selectors and separate them using an OR operator which is ||.
This will exclude:
window[‘location’][‘pathname’] != “/about-us” &&
window[‘location’][‘pathname’] != “/article-types/blogs”
This will include:
window[‘location’][‘pathname’] == “/about-us” ||
window[‘location’][‘pathname’] == “/article-types/blogs”
Excluding/Including with a specific portion of a URL segment
In some cases you will have a URL which contains multiple parameters, http://www.intilery.com/article-types/blogs, and you will want to exclude or include only pages that have one of those specific parameters in the URL. For example, you might want to exclude the custom module from the /blogs page but include it on the other /article-types pages. This is more complicated than the previous examples and requires the use of both the .split() and .indexOf() JS methods.
window[‘location’][‘pathname’].indexOf(‘/article-types’) > -1
window[‘location’][‘pathname’].indexOf(‘/article-types’) == -1
These two selectors check if a specific string exists within the URL section that we have specified, in this case it is checking to see if the string ‘/article-types’ exists within the pathname. The -1 on the right hand side of the statement denotes that it does not exist so the == operator will return false, the > operator will return true because the string does exist within the URL pathname.
Step-by-Step Excluding/Including URLs
- Navigate to the module that is applied to the campaign.
(Campaigns > Site Campaigns > Custom Modules > select the desired module through the menu on the left).
- Press Edit Code within the module (img a)
- Add the path of the web address you wish to exclude or include. Make sure to add this pathname contained within quotation marks as shown. (img c)
- Side note: To know if this is including or excluding this depends on the logic at the end of the statement. Simply, Exclude is, ending in == -1. Include is, ending in > -1.
- Then press Update > Save > Deploy > Deploy to Test (img d) (only Deploy to Live if you know this is working after testing!)