Step 2 - How to Initilize the CMP JS

To initialize the CMP, you need to call the “init” command and pass it a configuration object.

The “init” command triggers the initialization logic, which includes determining if the user should be prompted for consent based on Geolocation.  Any ad tag or other scripts that request consent from the CMP will be responded to after the CMP completes initialization.

The initialization process isn’t complete until the “init” call is made and the user has saved their consent preferences (if prompted).  The config object has the following properties.

  • Mandatory: config.uiUrl - (string) URL to the publisher hosted consent UI.
  • Optional: config.gdprAppliesGlobally - (boolean) True for EU targeted sites. Defaults to false.
  • Optional: config.uiDisplayMode: (string) - “iframe” renders UI in a modal iframe, “standalone” renders UI in a standalone page.  Defaults to “iframe”.
  • Optional: config.uiCustomParams (object) This is not used directly by the CMP JS.  It provides a way for publishers to pass any additional information to the CMP UI.

 

To initialize the CMP, perform the following steps:

  1. Open your preferred text editor and copy the following JavaScript code into a new file:

    <script>
    window.__cmp('init', {
        uiUrl: 'CONSENT_UI_URL',    
        gdprAppliesGlobally: GEO_DISPLAY_MODE,
         uiDisplayMode: 'UI_DISPLAY_MODE',
        uiCustomParams: {CONCENT_CUSTOMIZATION}
    });
    </script>


  2. Replace the placeholders in the configuration object (highlighted in red) with the relevant options according to the following table:

    Placeholder Mandatory Description Value Example
    CONSENT_UI_URL

     

     

    Yes 

    The URL address pointing to the Publisher's hosted consent User Interface. 

    String

    • Full URL
    uiUrl: 'https://www.example.com/cmp/cmpui.html', 
    GEO_DISPLAY_MODE

    No

    (False by default)

    Define if the consent form UI will be displayed only to EU Consumers or to All Consumers regardless of geolocation.

    Boolean

    • false (default)= EU Only
    • true = Everywhere

     

    gdprAppliesGlobally: false,
    UI_DISPLAY_MODE

    No

    (iFrame mode by default)

    Define how to render the consent UI in either an iFrame or in a standalone page in another browser tab.

    String

    • iframe (default)= Render in an iframe
    • standalone = render in another browser tab
    uiDisplayMode: iframe 
    CONCENT_CUSTOMIZATION

    No

    This is not used directly by the CMP JS.  It provides a way for publishers to pass any additional information to the CMP UI Object  

     

  3. Copy your completed initialization JavaScript code, and embed it into your site. The CMP will be invoked upon load.

  4. Continue to Step 3 - How to Brand Your Own Consent User Interface.
Have more questions? Submit a request