Meiro Events SDK public interface
MeiroEvents.init({} | string)
Sets an endpoint for events collection and configures other additional things like the external id, The Trade Desk synchronization, or domains for cross-domain tracking. It also:
-
generates unique user id
-
checks for inbound user ids from URL (cross-domain tracking)
-
appends CSS styles required for web banners functionality.
Input argument can be a string defining ME backend URL or config object with the following structure:
{
protocol?: "https:", // ME backend server protocol
domain: "events.meiro.io", // ME backend server domain
external_id?: "some-id", // some optional id sent with each event
the_trade_desk?: { // configuration for The Trade Desk synchronization
pid: "ttd-pid",
gdpr?: 0, // can be 1 or 0,
gdpr_consent?: "some consent string"
},
cross_domain_whitelist?: ["domain1", "domain2"]
}
MeiroEvents.getUserId(): string | null
:
Returns user ID.
MeiroEvents.getWebBannerId(): string | null
:
Returns visible Pop Up web banner id or null if there isn’t any.
MeiroEvents.getWebBannerName(): string | null
:
Returns visible Pop Up web banner name or null if there isn’t any.
MeiroEvents.closePopUpWebBanner()
:
Programmatically closes the visible web banner and dispatches meiro:bannerclose custom JavaScript event.
MeiroEvents.goToWebBannerUrl(url, bannerId)
:
Programmatically triggers the given web banner click and transitions a user to the given URL. It also dispatches meiro:bannerclick custom JavaScript event and sends web_banner_click event.
MeiroEvents.getWebBannerHttpResponses(bannerId): Response[]
:
If the given web banner makes HTTP requests in its conditions tree, the responses are stored for later usage in web banner HTML code (eg. you want to render some personalisation information from a segment API call). You simply don’t have to make the same API call again to get response data and you can access them via this method call.
The method returns an array of responses in the following format:
[
{
url: "https://cdp.meiro.io/wbs?customer_id=abcde&segment_id=5",
data: {
... response data
}
},
... possibly another banner api calls
]
MeiroEvents.showPopUpWebBanner(bannerId)
:
Renders Pop Up web banner specified in argument and closes previously displayed Pop Up web banner (if any). It also sends web_banner_impression event.
MeiroEvents.resetIdentity()
:
Restores all settings defaults and erases all information about the current user, specifically:
-
it closes opened Pop Up web banner (if any)
-
it completely clears storages
-
it removes user id cookies and inbound user ids cookie
-
it generates a completely new id
MeiroEvents.track(eventType, eventPayload?, bannerId): Promise
Main method used for tracking purposes, available variants are:
-
track(“page_view”, { optionalPayload })
-
sends
page_view
event and evaluates web banners conditions
-
-
track(“outbound_link_click”)
-
initializes tracking of outbound link clicks and decorates outbound URL for cross-domain tracking purposes if set
-
-
track("outbound_link_click", { domains_blacklist: ["
example1.com
", "
example2.com
"] })
Initializesinitializes tracking of outbound link clicks and decorates outbound URL for cross-domain tracking purposes if set. The second parameter is optional and contains domains blacklist configuration. When an outbound link leads to a domain listed indomains_blacklist
, the Outbound Link Click event is not tracked.domains_blacklist
is an array of strings.
-
track(“custom_event”, { payload })
-
sends
custom_event
with the given payload
-
-
track(“contact_form_submit”, { payload })
-
sends
contact_form_submit
event with the given payload
-
-
track(“web_banner_click”, { url: “destination url” }, bannerId)
-
sends
web_banner_click
event with the given destination URL for banner specified bybannerId
-