Prevent certain pages from showing the Wonderpush popup

marketing

#1

Hi all,

I had a small question. For a client of ours, we want to exclude some pages where the Wonderpush popup is not allowed to show. These are pages where we want the users to perform a certain action such as filling in a form and not be distracted by popups.

I already received some documentation on this and did an adjustment on the standard setup which you can find below. Based on these support pages, I added a piece of code that states the pages I want to exclude but I also had to add an extra part of code. I wanted to doublecheck if this other piece of code (see marked bold below) is necessary in order for the popup to not be shown on these pages and that it might conflict with our settings. To clarify this section, I also added a screenshot.

Could you have a look at this? Many thanks in advance!
Valerie

<script>
(function(w,d,s,i,n){w[n]=w[n]||{q:[],init:function(o){w[n].initOpts=o;},ready:function(c){w[n].q.push(c);}};
setTimeout(function(j,k){if(!d.getElementById(i)){k=d.getElementsByTagName(s)[0];j=d.createElement(s);j.id=i;
j.src="https://cdn.by.wonderpush.com/sdk/1.1/wonderpush-loader.min.js";k.parentNode.insertBefore(j,k);}},0);
}(window,document,"script","wonderpush-jssdk-loader","WonderPush"));

var locationsWithWonderPushOptinPluginsDisabled = [
    'page1',
  	'page2',
    // …
];

**var wonderpushInitOptions = {**
**  // … regular options like webKey and optInOptions**
**};**
**// Conditionnaly disable WonderPush opt-in plugins**
**if (locationsWithWonderPushDisabled.indexOf(location.pathname) >= 0) {**
**  // Ensure the `plugins` key exist, don't alter any other configuration otherwise**
**  if (!wonderpushInitOptions.plugins) wonderpushInitOptions.plugins = {};**
**  // Remove the optin plugins**
**  wonderpushInitOptions.plugins['optin-dialog'] = null;**
**  wonderpushInitOptions.plugins['optin-automatic'] = null;**
**}**  
  
WonderPush.init({
    webKey: "b03f3c6feba82059fba93e4dd219a3808c1699148a5686529b5c8b933690616e",
    optInOptions: {
        // You can modify or translate the following:
        externalBoxMessage: "Ontvangt u graag gepersonaliseerde notificaties van Klant A",
        externalBoxExampleTitle: "Voorbeeldnotificatie",
        externalBoxExampleMessage: "Dit is een voorbeeldnotificatie",
        externalBoxDisclaimer: "Je kan je op elke moment uitschrijven",
        externalBoxProcessingMessage: "Aanmelden...",
        externalBoxSuccessMessage: "Bedankt om je in te schrijven!",
        externalBoxFailureMessage: "Sorry, Er ging iets mis.",
        externalBoxTooLongHint: "Slechte verbinding of privé browsersessie geactiveerd?",
        externalBoxCloseHint: "Sluiten",
        modalBoxMessage: "We zullen je gepersonliseerde berichten sturen berichten op maat.<br/>Je kan je op elk moment uitschrijven.",
        modalBoxButton: "Ja graag!"
    }
});
  
</script>

#2

Hi,

You used the code of the How to prevent the opt-in dialog to show on some specific pages of my site? how-to but you made one mistake: the initialization options that originally were in the WonderPush.init({ … }); call should have been placed in the wonderpushInitOptions variable instead, and the last line initializing the SDK should have been left as in the how-to.

Here is the fixed code:

<script>
(function(w,d,s,i,n){w[n]=w[n]||{q:[],init:function(o){w[n].initOpts=o;},ready:function(c){w[n].q.push(c);}};
setTimeout(function(j,k){if(!d.getElementById(i)){k=d.getElementsByTagName(s)[0];j=d.createElement(s);j.id=i;
j.src="https://cdn.by.wonderpush.com/sdk/1.1/wonderpush-loader.min.js";k.parentNode.insertBefore(j,k);}},0);
}(window,document,"script","wonderpush-jssdk-loader","WonderPush"));

var locationsWithWonderPushOptinPluginsDisabled = [
    'page1',
    'page2',
    // …
];

var wonderpushInitOptions = {
    webKey: "b03f3c6feba82059fba93e4dd219a3808c1699148a5686529b5c8b933690616e",
    optInOptions: {
        // You can modify or translate the following:
        externalBoxMessage: "Ontvangt u graag gepersonaliseerde notificaties van Klant A",
        externalBoxExampleTitle: "Voorbeeldnotificatie",
        externalBoxExampleMessage: "Dit is een voorbeeldnotificatie",
        externalBoxDisclaimer: "Je kan je op elke moment uitschrijven",
        externalBoxProcessingMessage: "Aanmelden...",
        externalBoxSuccessMessage: "Bedankt om je in te schrijven!",
        externalBoxFailureMessage: "Sorry, Er ging iets mis.",
        externalBoxTooLongHint: "Slechte verbinding of privé browsersessie geactiveerd?",
        externalBoxCloseHint: "Sluiten",
        modalBoxMessage: "We zullen je gepersonliseerde berichten sturen berichten op maat.<br/>Je kan je op elk moment uitschrijven.",
        modalBoxButton: "Ja graag!"
    }
};
// Conditionnaly disable WonderPush opt-in plugins
if (locationsWithWonderPushDisabled.indexOf(location.pathname) >= 0) {
  // Ensure the `plugins` key exist, don't alter any other configuration otherwise
  if (!wonderpushInitOptions.plugins) wonderpushInitOptions.plugins = {};
  // Remove the optin plugins
  wonderpushInitOptions.plugins['optin-dialog'] = null;
  wonderpushInitOptions.plugins['optin-automatic'] = null;
}
// Initialize the WonderPush JavaScript SDK
WonderPush.init(wonderpushInitOptions);
  
</script>

Best


#3

Hi Olivier,

That really does explain it all! Thank you very much for the reply.

Valerie