jsakurai
Crownpeak Employee
Crownpeak Employee

How to test a site notice on a staging site (Domain Override)

While creating your notices you may want to traffic a production notice on a staging site to test it out before moving it up to production.  You can accomplish this by implementing a domain override inside of the UCP script.  

The domain override looks as follows:

setTimeout(function () {
                   window.evidon.notice.setDomain('<!-- Prod notice URL goes here -->');
               }, 2000);  

When the site initially loads our script will attempt to match the URL to a notice that has been setup in UCP.  Once the domain override runs it will force the notice for the URL inside of the domain override to populate on whichever site this override is placed on.  

To implement the domain override you will place it inside of our UCP script following all of the callback functions as you can see below: 

​<script type="text/javascript">
  (function (id) {
      function append(scriptid, url, async) {
          var d = document, sn = 'script', f = d.getElementsByTagName(sn)[0];
          if (!f) f = d.head;
          var s = d.createElement(sn);
          s.async = async;
          s.id = scriptid;
          s.src=url;
          s.charset = 'utf-8';
          f.parentNode.insertBefore(s, f);
      }

      function is2parttld(value) {
          var tldindicators = ['co', 'com', 'info', 'web', 'info', 'gov', 'edu', 'biz', 'net', 'org'];
          var countryindicators = ['uk', 'us', 'fr', 'es', 'de', 'at', 'au', 'ae', 'be', 'br', 'ca', 'ch', 'cn', 'co', 'cz', 'dk', 'eg', 'eu', 'fi', 'gb', 'gr', 'hk', 'hr', 'hu', 'ie', 'in', 'jp', 'mx', 'nl', 'no', 'nz', 'pl', 'ro', 'ru', 'se'];
          return (tldindicators.indexOf(value) !== -1 || countryindicators.indexOf(value) !== -1);
      }

      function getRootDomain() {
          var parts = window.location.hostname.split('.');
          if (parts.length === 2) rootDomain = parts[0];
          else if (parts.length > 2) {
              // see if the next to last value is a common tld
              var part = parts[parts.length - 2];
              if (is2parttld(part)) {
                  rootDomain = parts[parts.length - 3]; // go back one more
              }
              else {
                  rootDomain = part;
              }
          }

          return rootDomain;
      }

      window.evidon = {};
      window.evidon.id = id;
      window.evidon.test = false;  // set to true for non-production testing.
      //window.evidon.userid = '';

      var cdn = '//c.evidon.com/', rootDomain = getRootDomain(), noticecdn = cdn + 'sitenotice/';
      append('evidon-notice', noticecdn + 'evidon-sitenotice-tag.js', false);
      append('evidon-location', cdn + 'geo/country.js', true);
      append('evidon-themes', noticecdn + id + '/snthemes.js', true);
      if (rootDomain) append('evidon-settings', noticecdn + id + '/' + rootDomain + (window.evidon.test ? '/test' : '') + '/settingsV2.js', true);

      window.evidon.priorConsentCallback = function (categories, vendors, cookies) {
          // add the tags which need to wait for prior consent
          // here.  This should be all your advertising tags and
          // probably most of your social and tracking tags.
          
      }

      window.evidon.closeCallback = function () {
          // this is executed if the user closed a UI element without either Accepting (providing consent)
          // or Declining (declining to provide consent).
      }

      window.evidon.consentWithdrawnCallback = function () {
          // this is exeucted if the user withdraws consent and elects to
          // no longer allow technologies to run on the site.
      }

      window.evidon.consentDeclinedCallback = function () {
          // this is executed if the user explicitly declines giving consent by
          // using a Decline button
      }
      setTimeout(function () {
                   window.evidon.notice.setDomain('<!-- Prod notice URL goes here -->');
               }, 2000);
  })(xxxx);
Labels (1)

Can't find what you are looking for?

Find Answers

Search our DG Forum to find answers to questions asked by other DG users.

Ask a Question

No luck? Ask a question. Our Product and Support teams are monitoring the Forum and typically respond within 48 hours.

Ask a Question