Tue May 15 2018
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306

<script>
  // Sent GTM events if user accepts on this page to fire tags
  // If cookies are already present, GTM Page view rules will take care of it.
  (function () {
    window.gdpr.on("gdpr_accept_analytics_only", function () {
      console.log("ANALYTICS cookies")
      dataLayer.push({ 'event': 'gdpr_analytics_allowed' });
    })

    window.gdpr.on("gdpr_accept_all_cookies", function () {
      console.log("All cookies")
      dataLayer.push({ 'event': 'gdpr_analytics_allowed' });
      dataLayer.push({ 'event': 'gdpr_pixel_allowed' });
    })
  })
</script>

<script>
  (function () {

    // **************************************************
    // COUNTRY CODE IP LOOKUP
    //     reference: https://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements (see column: Alpha-2 code)
    // **************************************************
    function loadCountryCode() {

      var api_url = 'https://www.rosettastone.com/gils';

      function load(url, callback) {
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
          if (xhr.readyState === 4) {
            callback(xhr);
          }
        }
        xhr.open('GET', url, true);
        xhr.send();
      }

      function handler(data) {
        // this looks for https://www.rosettastone.com/gils/CC (where CC is the country code such as US, DE, FR, or whatever)
        // if there's no country code available, the response will be /gils
        var country_code = (data.responseURL.match(/gils\/(\w+)/i) || ['', ''])[1];

        if (country_code) {
          window.gdpr && window.gdpr.change_country_code(country_code);
        }
      }

      load(api_url, handler);

    }
    if (!getCookie('gdpr_country_code')) {
      loadCountryCode();
    }




    // *******************************************************
    // Initialize global gdpr variable
    // *******************************************************

    window.gdpr = window.gdpr || {
      country_code: getCookie('gdpr_country_code') || '',

      cookie_consent: getCookie('gdpr_cookie_consent') || null,
      email_consent: null,

      double_opt_in_countries: ['DE', 'CA'],

      change_country_code: function (new_country_code) {
        window.gdpr.country_code = new_country_code;
        setCookie('gdpr_country_code', new_country_code);

        window.gdpr.trigger('changed_country_code');
        return new_country_code;
      },

      max_wait_for_country_code: 500,

      events: {},

      on: function (event, callback) {
        this.events[event] = this.events[event] || [];
        this.events[event].push(callback);
      },

      trigger: function (event) {
        if (this.events[event]) {
          this.events[event].forEach(function (callback) {
            callback();
          });
        }
      }
    };











    // *******************************************************
    // Cookie helper functions
    // *******************************************************

    // get cookie
    function getCookie(cookie_name) {
      var regex = new RegExp('(^|;\\s)' + cookie_name + '=([^;]+)', 'i');
      return (document.cookie.match(regex) || [])[2];
    }

    // set cookie for 30 days
    function setCookie(name, value) {
      var exp = new Date(Date.parse(new Date()) + (30 * 24 * 60 * 60 * 1000));
      var domain = window.location.hostname.replace(/www/i, ''); // domain isolation is tricky, so this will cover the majority of use cases
      document.cookie = name + '=' + value + '; path=/; expires=' + exp + '; domain=' + domain;
    }

    // delete cookie
    function deleteCookie(name) {
      var domain = window.location.hostname.replace(/www/i, '');
      document.cookie = name + '=; domain=' + domain + '; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    }


  })();
</script>

<!-- OneTrust Cookies Consent Notice (Production CDN, rosettastone.com, en-GB) start -->

<!-- <script src="https://cdn.cookielaw.org/consent/085baa86-593a-4abd-891f-f273486ebd94.js" type="text/javascript" charset="UTF-8"></script> -->

<script type="text/javascript">

  (function () {

    // max wait time for API to return country code
    var max_wait_for_country_code = (window.gdpr && window.gdpr.max_wait_for_country_code || 500);


    // initialize onetrust popup (with url given in onetrust dashboard)
    var onetrust_popup_url = 'https://cdn.cookielaw.org/consent/085baa86-593a-4abd-891f-f273486ebd94.js';
    initialize_onetrust_popup(onetrust_popup_url);


    // determine what to do with popup after country code wait
    setTimeout(function () {


      // unblock cookie consent popup if user is NOT from US
      if (!(window.gdpr && window.gdpr.country_code === 'US')) {
        unblockOneTrust();
      }


      // this runs on page load and every time user updates cookie preferences
      function OptanonWrapper() {
        console.log("OptanonWrapper")
        if (window.OptanonActiveGroups) {

          var all_cookies_accepted = (/,4,/).test(window.OptanonActiveGroups);
          var analytics_cookies_accepted = (/,(2|3),/).test(window.OptanonActiveGroups);
          var no_cookies_accepted = window.OptanonActiveGroups === ',1,';

          if (all_cookies_accepted) {
            console.log("all_cookies_accepted");
            window.gdpr && window.gdpr.trigger('gdpr_accept_all_cookies');
          }
          else if (analytics_cookies_accepted) {
            console.log("analytics_cookies_accepted");
            window.gdpr && window.gdpr.trigger('gdpr_accept_analytics_only');
          }
          else if (no_cookies_accepted) {
            console.log("no_cookies_accepted")
            window.gdpr && window.gdpr.trigger('gdpr_revoke_cookie_consent');
          }
        }
      }



      // Rosetta Stone's custom fixes ensure OneTrust's dark overlay appears and disappears when it should
      perform_onetrust_fixes();

    }, max_wait_for_country_code);










    // ******************************************************
    // Utility functions
    // ******************************************************


    function initialize_onetrust_popup(onetrust_url) {
      var onetrust = document.createElement('script');
      onetrust.setAttribute('src', onetrust_url);
      onetrust.setAttribute('type', 'text/javascript');
      onetrust.setAttribute('charset', 'UTF-8');
      document.head.appendChild(onetrust);

      // make sure onetrust popup starts temporarily hidden while code decides whether to show it
      blockOneTrust();
    }

    function blockOneTrust() {
      var one_trust_hider = document.createElement('style');
      one_trust_hider.setAttribute('id', '__gdpr_onetrust_hider');
      var one_trust_hider_css = ''
        + '#optanon, .optanon-alert-box-wrapper{'
        + 'display: none !important;'
        + '}'
        + '';
      one_trust_hider.innerHTML = one_trust_hider_css;
      document.querySelector('head').appendChild(one_trust_hider);
    }

    function unblockOneTrust() {
      var one_trust_hider = document.getElementById('__gdpr_onetrust_hider');
      document.querySelector('head').removeChild(one_trust_hider);
    }


    function perform_onetrust_fixes() {

      function fadeOut(selector, duration, callback) {
        duration = duration || 400;

        var elems = Array.prototype.slice.call(document.querySelectorAll(selector));
        elems.forEach(function (elem) {
          elem.style.transition = 'opacity ' + duration + 'ms';
        });
        setTimeout(function () {
          elems.forEach(function (elem) {
            elem.style.opacity = 0;
          });
        }, 0);
        setTimeout(function () {
          elems.forEach(function (elem) {
            elem.style.display = 'none';
          });

          callback && callback();
        }, duration);

      }

      function fadeIn(selector, duration, callback) {
        duration = duration || 400;

        var elems = Array.prototype.slice.call(document.querySelectorAll(selector));
        elems.forEach(function (elem) {
          elem.style.transition = 'opacity ' + duration + 'ms';
          elem.style.display = 'block';
        });
        setTimeout(function () {
          elems.forEach(function (elem) {
            elem.style.opacity = 1;
          });
        }, 0);

        setTimeout(function () {
          callback && callback();
        }, duration);
      }

      function getElems(selector) {
        return Array.prototype.slice.call(document.querySelectorAll(selector));
      }

      // Rosetta Stone's custom fixes ensure OneTrust's dark overlay appears and disappears when it should
      setTimeout(function () {
        getElems('.optanon-alert-box-close').forEach(function (elem) {
          elem.addEventListener('click', function () {
            fadeOut('#optanon-popup-bg', 400, blockOneTrust);
          });
        });
        getElems('.optanon-close-link').forEach(function (elem) {
          elem.addEventListener('click', function () {
            setTimeout(function () {
              fadeIn('#optanon-popup-bg', 400);
            }, 500);
          });
        });
      }, 1000);
    }

  })();


</script>

<!-- OneTrust Cookies Consent Notice (Production CDN, rosettastone.com, en-GB) end -->