Thu May 10 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
<script>
(function(){

  // *******************************************************
  // Get country code from the url (example: US)
  //     reference: https://en.wikipedia.org/wiki/ISO_3166-1#Officially_assigned_code_elements (see column: Alpha-2 code)
  //
  //     if you're using an api to get country code after page load,
  //     use this for example:
  //         window.gdpr && window.gdpr.change_country_code('DE');
  // *******************************************************

  // edit inside this function if you have a different way to get the two letter country code on page load
  function get_country_code(url){

    // country code should come from url parameter from NGINX rule (example: country=US)
    var country_code = (url.match(/[&?]country=([^&]+)/i) || ['',''])[1].toUpperCase();
    if(country_code){
      setCookie('gdpr_country_code', country_code);
    }

    return country_code;
  }



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

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

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

    double_opt_in_countries: ['DE'],

    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;
    },

    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();
        });
    	}
    }
  };






  // *******************************************************
  // 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));
    document.cookie = name+'='+value+'; path=/; expires='+exp+'; domain=.rosettastone.com';
  }

  // delete cookie
  function deleteCookie(name) {
    document.cookie = name+'=; domain=.rosettastone.com; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  }


})();
</script>