Setting tags for overlays

During normal use Ometria's script initialises all of the plugins when the init method is called.

This is likely to cause an issue for you if you want to set some tags before the request is sent.

There are a number of plugins (e.g. Shopify) that set a value called auto_init to true, causing the script to run its init method without any interaction from your code and, in turn, initialising all of the plugins.

Manually call init

To prevent the overlays plugin from initialising before you've set all of the tags you want to set, you should manually call init on the overlays plugin.

To prevent the plugin from running as part of an auto_init change your script tag from:

<script src="cdn.ometria.com/tags/<ACCOUNT_HASH>">

to:

<script id="ometria-script" data-overlay-init="manual" src="cdn.ometria.com/tags/<ACCOUNT_HASH>">

Usage

Once set up, there should be a new object at window.ometria.overlay which you can call with your code.
You can set as many tags as you like.

The array of tags is sent in the payload to Ometria's API, which uses them (along with the other settings) to determine which overlay to return.

📘

Note

The payload sent to Ometria will always include the tag property even if the set up steps haven’t been carried out. The default value to tag is an empty array and should not have any effect on which overlay Ometria chooses to return

In contrast, the ometria.overlay object will not exist if the set up steps haven’t been carried out.

Overlay tag methods

The following methods are available on window.ometria.overlay:

setTag

Pushes a new tag into the tags array:

// Initial state: { tag: ['one'] }  
ometria.overlay.setTag('two');  
// Result: { tag: ['one', 'two'] }

setTags

Pushes multiple new tags into the tags array:

// Initial state: { tag: ['one', 'two'] }  
ometria.overlay.setTags(['three', 'four']);  
// Result: { tag: ['one', 'two', 'three', 'four'] }

unsetTag

Removes a tag from the array:

// Initial state: { tag: ['one', 'two', 'three', 'four'] }  
ometria.overlay.unsetTag('two');  
// Result: { tag: ['one', 'three', 'four'] }

init

Initialises the plugin which will then make the call to the DCAPI

// Initial state: { tag: ['one', 'two', 'three', 'four'] }
ometria.overlay.init()
// Result: Payload to DCAPI includes { tag: ['one', 'two', 'three', 'four'] }