Skip to main content

ATS.js Functions and Events

Learn about the ATS.js functions you can use for specific tasks and the events that ATS.js fires.

ATS.js Functions

ats.retrieveEnvelope(callback);

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

ats.outputCurrentConfiguration();

This will return the current configuration object. The callback function is optional. In both ways it will return the current config object.

ats.triggerDetection();

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

ats.invalidateEnvelope();

This function will remove the current envelope that is stored in local storage/cookie.

ats.setAdditionalData(data);

If Direct Mode is enabled, this function can be called with object and properties: consentString, consentType (can be 'gdpr' if type of consent is tcf2 for EU or 'ccpa' if consent string is for USA), id (identifier) and type of identifier.

Type parameters are: email, phoneNumber, and emailHashes.

You can also pass custom IDs if you do not work with any of the valid type parameters. See "Custom ID Support" to learn more.

Example of function:

ats.setAdditionalData({ 
  consentString: 'CO4ZAMCO4fAnQADABCENAzCgAP_AAEOAAAAAAwwAgAEABhAAgAgAAA.YAAAAAAAAAA', 
  consentType: 'gdpr', 
  id: 'email@liveramp.com', 
  type: 'email'
});

Events

lrEnvelopePresent

This event will be fired when a new or existing identity envelope is stored in configured storage.

Example:

    // An ATS envelope has been located!
    window.addEventListener("lrEnvelopePresent", async () => {
        console.log("lrEnvelopePresent: ", await atsenvelopemodule.retrieveEnvelope());
    });

detectionModuleReady

This event will be fired when the detection module (for detecting the identifier on page) is fully loaded.

Example:

    // ATS detection module is ready to be used.
    window.addEventListener("detectionModuleReady", () => {
        atsdetectionmodule.outputCurrentConfiguration();
    });

envelopeModuleReady

This event will be fired when the envelope module (for creating an identity envelope and storing it in configured storage) is fully loaded.

Example:

// ATS envelope module is ready to be used.
    window.addEventListener("envelopeModuleReady", () => {
        // For example, you can directly feed it emails, like so:
        atsenvelopemodule.setAdditionalData({
            'type': 'email',
            'id': "test@liveramp.com"
        });
    });

dropMatchPixelModuleReady

This event will be fired when the Match Pixel Module (for dropping Match Pixel on the page) is fully loaded.