6. Return Stored Identity Envelopes

For troubleshooting purposes and as required by vendors, such as Prebid.js, you will need to implement a mock function and expose it where you are resolving users to envelopes, preferably on every page.

Other vendors on the publishers page should be able to make a call to window.ats.retrieveEnvelope() and receive a JSON object, e.g.:

{"envelope":"AtkoTqF8plPFYr2r2QgpbhKhY_XWhJrmI0gSSTulk24dzDKTlNOf4A"}

If no envelope is available, it will return as undefined.

Return an Identity Envelope From a First-Party Cookie

Assuming your Identity Envelope is stored in the first-party cookie _lr_env, the below function will look up the envelope (if it exists) and return it to the caller.

function retrieveEnvelope(callback) {
  let env = undefined;
  try {
    env =
 decodeURIComponent(document.cookie.match('(^|;) *_lr_env=([^;]*)')[2]);
      env = {
          'envelope': JSON.parse(atob(env)).envelope
      };
env = JSON.stringify(env);
  } catch (e) {
    console.log(e);
  } finally {
    if(callback){
      callback(env);
    } else {
      return env;
    }
  }
}
window['ats'] = {};
window.ats.retrieveEnvelope = retrieveEnvelope;

Return an Identity Envelope From Local Storage

Assuming your Identity Envelope is stored in local storage under key _lr_env, the below function will look up the envelope (if it exists) and return it to the caller.

function retrieveEnvelope(callback) {
  let env = undefined;
  try {
    env = {
       “envelope”: window.localStorage.getItem(‘_lr_env’)
    };
env = JSON.stringify(env);
  } catch (e) {
    console.log(e);
  } finally {
    if(callback){
      callback(env);
    } else {
      return env;
    }
  }
}
window[‘ats’] = {};
window.ats.retrieveEnvelope = retrieveEnvelope;