ats.js Functions

ats.start(config);

Typically, ats.start(config); is the only function you will need to call.

This function should be placed into its own <script> tag and called with your configuration object just after the <script> tag for ats.js. The library will not begun to run processing or detection until it is started.

ats.retrieveEnvelope(callback);

Fetch envelope from configured storage; the callback function is optional. If the function is called without a callback, a promise will be returned. If function is called with callback, an envelope value will be returned.

Retrieving envelopes from an iframe

You can call for envelopes from within an iframe (or nested iframe) using postMessage. As an example, implementing the following will request an envelope from the parent:

function dispatchEnvelopeRequestEvent() {
        try{
            top.postMessage('ats-liveramp-envelope-request','*');
        }catch(e){
            if(typeof(winRef.contentWindow) != 'undefined') {
                top.contentWindow.postMessage('ats-liveramp-envelope-request','*');
            }
        }
    }

You will then need to receive and process the result from the parent.

function receiveEnvelope(event) {
        if(event && event.data && event.data.message === 'ats-liveramp-envelope-result'){
            console.log(event.data.result,event.origin);
        }
    }
    window.addEventListener('message', receiveEnvelope, false);

ats.triggerDetection();

This function will (re)scan DOM elements with the CSS selectors specified in your configuration. You can call this function if the ats.js library has been started.