> For the complete documentation index, see [llms.txt](https://docs.navigaglobal.com/engage/-MGi9-KKLwnWfoD36Ot6/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.navigaglobal.com/engage/-MGi9-KKLwnWfoD36Ot6/getting-started-with-engage/configuring-engage-on-your-website/setting-up-the-inititalization-script.md).

# Setting up the Initialization Script

Once your configuration is set up, you can download the Engage plugin for your website using the loader CDN URL. The standard Engage initialization flow using the Loader URL is as follows:

* You add the Loader CDN URL (script tag with source <https://loader-cdn.azureedge.net/prod/\\[clientCode]/loader.min.js>) followed by the Engage Init script into either the`<head>` or the `<body>` tag on every page of your website. The exact method of propagating this code to all your pages can vary depending on the CMS that is used to manage your website.
* The Loader CDN URL downloads the loader-Config.json file. The loader-Config.json file contains the URLs from where the loader then downloads the Engage plugin, the FingerPrint plugin, and the G2Insights plugin. The Audience plugins (Engage, FingerPrint, and G2Insights) are fetched from Naviga-managed CDN.
* Once plugins are fetched, Loader initializes them passing the plugin-specific part of the initialization script.

{% hint style="warning" %}
Prior to version 2.7.2, Engage requires jQuery 3.0 or higher to function.
{% endhint %}

<details>

<summary>CName Approach</summary>

#### Context:

The loading of the Engage Plugin on your site can be blocked by the Adblockers enabled on readers’ browsers. An Adblocker generally blocks those URLs on a website that appear to be third-party URLs. Whenever Engage CDN URLs are mistakenly identified as third-party URLs by the Adblockers, the URLs cannot bypass the Adblockers set on the browsers. This problem is particularly observed when Adblockers such as AdBlock Ultimate, UBlock, Ghostery, or similar ones are activated on the browsers.

To resolve this issue, it is recommended to implement the CName(Canonical Name) approach.&#x20;

#### What must you do?

1. &#x20;You should create four subdomains using your specific clientCode/clientName such as:\
   a. **loader.\<clientname>.com** --> For ***loader.min.js*** and for ***loader-config.json***\
   *b.* **Engage.\<clientname>.com** --> For ***t8y9347t.min.js*** and ***t8y9347t.min.css***\
   *c.* **Fp.\<clientname>.com** --> For ***fp.min.js***\
   *d.* **G2i.\<clientname>.com** --> For ***g2i.min.js***
2. &#x20;Share the newly created subdomain names with your Project Manager to pass them on to the Engage team.
3. These sub-domains must then be directed/pointed to Engage CDN endpoints.<br>

   *(Note: This step enables Engage to bypass any Adblocker set on the readers’ browsers. We can make sure that the loading of Engage plugins is uninterrupted and not affected by any Adblockers.)*

   For example,\
   loader.\<clientname>.com should direct to -> loader-cdn.azureedge.net\
   Engage.\<clientname>.com should direct to -> connext-cdn.azureedge.net\
   Fp.\<clientname>.com should direct to -> fp-cdn.azureedge.net\
   G2i.\<clientname.com> should direct to -> g2insights-cdn.azureedge.net
4. The new client sub-domains must be whitelisted in Engage CDN endpoints. The whitelisting ensures that the new subdomains are recognized as legitimate and can access Engage resources without issues.

#### Note:

Below is an example of a loader URL following the CName approach:

New URL: <https://loader.\\><clientname>.com/prod/\<clientCode>.loader.min.js

Example: <https://loader.naviga.com/prod/nvg.loader.min.js>

</details>

Below is a sample version of the scripts for a production environment:

```javascript
<script src="https://loader-cdn.azureedge.net/prod/client/loader.min.js"></script>
<script> MG2Loader.init({  

      plugins: [{  
            name: "FP",  
            initOptions: {  
                  version: "client",  
                  environment: "prod"  
            }  
      }, {  

            name: "DL",  
            initOptions: {  
                  version: "client",  
                  collectors: ["connext"],  
                  tagManager: "GTM",  
                  containerId: "GTM-###### "  
            }  
      }, {  
            name: "NXT",  
            initOptions: {  
                  clientCode: "client",  
                  environment: "prod",  
                  siteCode: "client",  
                  configCode: "client",  
                  debug: false,
                  // the below is optional and used 
                  // if you want to initialize Engage manually  
                  // IMPORTANT: if Engage is not initialized manually
                  // remove the two properties below
                  silentmode: true, 
                  runSettings: { 
                        runOffset: 3000 
                  } , 
                  configSettings: { 

                  }, 
                  resourceUrl: “”, 
                  settingsKey: “client”, 
                  pluginStartTime: { 

                  }, 
                  productCode: “”, 
                  apiUrl: “engage”, 
                  // Optional 
                  integrateFlittz: false, 
                  publicEventHandlers: { 

                  }, 
                  appInsightsKey: “g2i”, 
                  loadType: { 
 
                  }, 
                  authSettings: { 
 
                 }, 
                 swgSettings: { 

                 }, 
                 userAuthenticationTime: 0, 
                 userIgmAuthTime: 0, 
                 tracingSettings: { 

                  }, 
                  traceLevel: { 

                  }, 
                  debugTraceExpirationSettings: { 

                   }, 
                  ViewsUpdateFroServerPeriod: 0, // in hours 
                  ConversationPromiseTimeout: 0, // in milliseconds 
                  ActionPromiseTimeout: 0, // in milliseconds 
                  DynamicMeterPromiseTimeout: 0 // in milliseconds 
                  articleIdProvider: function(){ }, 
                  checkUserDataEveryPageload: false,  
                  // End optional 
                  batchCount: 0, 
                  attr: { 

                  }, 
                  sessionId: “engage”, 
                  publishData: { 

                  }, 
                  externalMigrationCode: “”, 
                  integrateDisqus: false 
                 
            }  
      }]  
})
</script>
```

{% hint style="info" %}

* To avoid any timing and page rendering issues, it is ideal to place the initialization code towards the end of the page, just inside the closing`</body>`tag. This ensures that all the DOM elements are already present on the page before the script starts loading.&#x20;
* It's also recommended to place the Engage initialization script as the **first script within the list of scripts loaded at the end of the body tag**, but again, make sure that it is AFTER all the DOM objects are loaded.
  {% endhint %}

### Initialization Script Options

The initialization script contains the necessary `initOptions` that define the settings for each of your Audience plugins: Fingerprint (`"FP"`), G2Insights (`"DL"`), and Engage (`"NXT"`). All the values passed within `initOptions` must be separated by commas.\
Below you'll find a list of the essential Engage options and their properties.&#x20;

<table data-header-hidden><thead><tr><th>Option Name</th><th width="225.33333333333331">Description</th><th>Parameters</th></tr></thead><tbody><tr><td>Option Name</td><td>Description</td><td>Parameters</td></tr><tr><td><code>clientCode</code></td><td>Mandatory. The constant variable representing your publication, provided by your Project Manager. </td><td>e.g. <code>"My-Newspaper"</code></td></tr><tr><td><code>siteCode</code></td><td>Mandatory. This is the site code that will be provided by your Project Manager. If it's missing or invalid, Engage will not be able to initialize.</td><td>e.g. <code>"MNPP"</code></td></tr><tr><td><code>environment</code></td><td><p>Optional, defaults to <code>prod</code>. This option sets the testing environment for your website and determines the relevant database and website where Engage is to be deployed.<br></p><p>If the <code>environment</code> option property is missing, Engage will search for the environment details in the website's URL. If none are found, the <code>"prod"</code> property will be passed. </p></td><td><p></p><ul><li><code>"stage"</code> – for staging environments</li><li><code>"prod"</code> – for production environments<br>(The property used by default is "prod"). </li></ul></td></tr><tr><td><code>configCode</code></td><td>This is the <a href="/engage/-MGi9-KKLwnWfoD36Ot6/fundamentals/configurations.md#code">code of your configuration</a> containing all your Engage settings. The code is defined in the <a href="/engage/-MGi9-KKLwnWfoD36Ot6/fundamentals/configurations.md"><strong>Configurations</strong></a> tab of your Engage dashboard.</td><td>e.g. <code>"CONFIG"</code></td></tr><tr><td><code>debug</code></td><td>If set to <code>true</code>, will open the Engage debug panel by default. Should be set to <code>false</code> in production.</td><td><ul><li>Boolean</li></ul></td></tr><tr><td><code>silentmode</code></td><td>This option can be used if you would like to initialize Engage manually by running the <code>Connext.Run()</code>method. </td><td><p></p><ul><li><code>"true"</code> – Engage will not start initializing until you use the <code>Connext.Run()</code> command;</li><li><p>"false" – Engage will initialize as usual according to your settings.</p><p>The default property is <code>"false"</code>.</p></li></ul></td></tr><tr><td><code>runSettings</code></td><td><p>This option defines specific parameters that can be used to run the Engage plugin.</p><p></p><p></p></td><td><ul><li><code>runPromise</code> – uses a JavaScript Promise object based on the fulfilled/rejected status of which Engage will run. This is useful if you would like the plugin to start after some other process;</li><li><code>onRunPromiseResolved</code> – a callback function which is called when <code>runPromise</code> is fulfilled (by default when <code>Connext.Run()</code> is executed).</li><li><code>onRunPromiseRejected</code> – a callback function which is called when <code>runPromise</code> is rejected;</li><li><code>runOffset</code>– a delay in milliseconds after which Engage will run (in case the Promise object did not return any results). By default, <code>runOffset</code> is 5000 milliseconds (if <code>runSettings</code> are present but <code>runOffset</code> is not).</li></ul></td></tr><tr><td>resourceUrl</td><td>Defines url for downloading plugins.</td><td>e.g. “"https://cdn.someurl.xyz/stage/clientCode”</td></tr><tr><td>settingsKey</td><td>This option is used to handle sub-sections of the site.</td><td>e.g. “sports"</td></tr><tr><td>configSettings</td><td>Defines some settings which should be merged with config settings from DB.</td><td>e.g. {“ EnforceUniqueArticles”: false}</td></tr><tr><td>productCode</td><td>Defines product code.</td><td>String</td></tr><tr><td>apiUrl</td><td>This option stores url to engage API</td><td>e.g. “https://271-api-connext.azurewebsites.net/”</td></tr><tr><td>integrateFlittz</td><td>Used to integrate Flittz platform</td><td>Boolean</td></tr><tr><td>publicEventHandlers</td><td>This option defines a list of callbacks that can be used to handle specific events.</td><td><p>onNotAuthorized, </p><p>onAuthorized, </p><p>onHasNoActiveSubscription, onHasAccessNotEntitled, onHasAccess; </p></td></tr><tr><td>appInsightsKey</td><td>This option is used to store data to AppInsight and then to get this data by this value.</td><td>e.g. “nxt”</td></tr><tr><td>loadType</td><td>This option defines how to load data.</td><td>e.g. “ajax”</td></tr><tr><td><p>authSettings</p><p><br><strong>Note</strong>: <br>The parameters seamlessSISO is available from 2.8.6, seamlessSO is available from 2.8.6.1, and enableAuth0JwtCookie is available from 2.8.3.2.<br><br>The seamlessSISO parameter is renamed to seamlessSI from 2.8.7. </p></td><td>This option defines some values for authentication.</td><td><p>{ </p><p>    "domain": "site.com", </p><p>    "client_id":"some_secret_key", </p><p>    "redirect_uri":"https://www.site.com/login-redirect/", </p><p></p><p>seamlessSISO: true/false,</p><p></p><p>seamlessSO: true/false,</p><p></p><p>enableAuth0JwtCookie: true/false,</p><p>    "cacheLocation":"localstorage" </p><p>} </p></td></tr><tr><td>swgSettings</td><td>This option defines properties to configure Subscribe with Google feature.</td><td><p>{ </p><p>“</p><p>DataMarkup”:”string”, </p><p>“GoogleClientId”:”string”, </p><p>“SwgJs”: “string”, </p><p>“JsonpCallback”:”string”, </p><p>“ForceAccountLinking”: false </p><p>} </p></td></tr><tr><td>userAuthenticationTime</td><td>Defines amount of days of life of auth cookie’s value</td><td>Number</td></tr><tr><td>userIgmAuthTime</td><td>Defines amount of days of life of IGM auth cookie’s value</td><td>Number</td></tr><tr><td>tracingSettings</td><td>Defines settings of tracing logs.</td><td><p>{ </p><p>“TraceLevel”: 0, </p><p>“DebugTraceExpirationSettings”:{ </p><p>“Duration”: 0, </p><p>“StopAfter”: 0, </p><p>“ConfigCode”: “string” </p><p>} </p></td></tr><tr><td>traceLevel</td><td>Defines which level of logs to trace. (Debug, Error, Fatal, None)</td><td>Number</td></tr><tr><td>debugTraceExpirationSettings</td><td>Defines when tracing settings expire.</td><td><p>{ </p><p>“Duration”: 0, </p><p>“StopAfter”: 0, </p><p>“ConfigCode”: “string” </p><p>} </p></td></tr><tr><td>ViewsUpdateFromServerPeriod</td><td>This option defines how often Engage should update views (In hours).</td><td>Number</td></tr><tr><td>ConversationPromiseTimeout</td><td>This option defines how long conversation calculation can take (In milliseconds).</td><td>Number</td></tr><tr><td>ActionPromiseTimeout</td><td>This option defines amount of time to resolve action (In milliseconds).</td><td>Number</td></tr><tr><td>DynamicMeterPromiseTimeout</td><td>This option defines amount of time to resolve dynamic meter (In milliseconds).</td><td>Number</td></tr><tr><td>articleIdProvider</td><td>Optional. This option defines a function that returns articleId.</td><td>Function</td></tr><tr><td>checkUserDataEveryPageload</td><td>Optional. This option turns on refreshing user data on every pageload instead of updating it once in 24 hours.</td><td>Boolean </td></tr><tr><td>batchCount</td><td>Defines count of requests after which Engage sends view request to the server.</td><td>By default 3.</td></tr><tr><td>attr</td><td>Additional attribute for config’s name</td><td>String</td></tr><tr><td>sessionId</td><td>This option helps to identify actions per session.</td><td>String</td></tr><tr><td>publishData</td><td>Contains information about the last published configuration.</td><td>e.g. {"publishSettings" :{"ResetArticleViews": false, "ResetAllowIpList": false, "ResetCurrentConversation": false, "ResetRepeatable": false, "ResetDaysVisitedSite": false, "PluginDebugAllowed": true, "Date":"2022-03-30T20:34:56+00:00"}, "needUpdate":false}</td></tr><tr><td>externalMigrationCode</td><td>Defines code migrations.</td><td>String</td></tr><tr><td>integrateDisqus</td><td>This option is used to add Disqus integration</td><td>Boolean</td></tr></tbody></table>

## Init Parameters

### authSettings

1. **seamlessSI** - If this parameter is set to 'true', it enables seamless sign-in functionality across your sister websites. The Seamless Sign-In feature allows visitors to stay logged in to your other sister websites if they are already logged in on any of your websites.
2. **seamlessSO** - With this parameter, you can configure the lastlogoutDate API call. When the parameter "SeamlessSO: true" is present in the initOptions, Engage triggers the lastlogoutDate API call on every page load. If this parameter is absent in the initOptions or if its value is 'false', then the lastlogoutDate API call is not triggered on every page load.
3. **enableAuth0JwtCookie** - If this parameter is set to 'true' in initOptions, the Engage plugin drops a cookie 'auth0\_jwt' with the contents of Auth0 JSON web token that has the access details, and Engage allows server-side paywalls on your website.
4. **enableActiveIdTokenFlow** - If this parameter is set to 'true' in initOptions, upon successful user login, the `auth0_jwt` cookie will store the ID token received from Auth0, with an expiry time the same as that of the ID token of the Auth0 local storage object.

{% hint style="info" %}
**Server-side paywalls:**

As the name implies, it is a mechanism used to restrict access to content or services on your website from the website server. The implementation of the server-side paywall and its functioning is completely the client's responsibility.
{% endhint %}
