ePrivacy and GPDR Cookie Consent by Cookie Consent Skip to main content

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
  path?: "/events", // Path where ME backend server expects events (default is '/')
  endpoint?: "https://events.meiro.io/events", // specifies the whole ME backend endpoint, 'protocol', 'domain' and 'path' will be ignored in this case
  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"],
storage_consents?: { statistics: true } // optional property that specifies consent by category where true means consent was given and  false means it was not
  sync?: {  // configuration for automatic collection of FB, Google and Optimizely data
    ga_cid: true,
    fb_cid: true,
    optimizely: true
  }
}

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({ minimize?: boolean }):

Programmatically closes the visible web banner and dispatches meiro:bannerclose custom JavaScript event. Accepts configuration object with minimize property suitable for web banners with minimized version where you can specify, if you want to minimize web banner or not (default is true).

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:

    • sends page_view event and evaluates web banners conditions

    • initializes tracking of outbound link clicks and decorates outbound URL for cross-domain tracking purposes if set

    • initializes 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 in domains_blacklist, the Outbound Link Click event is not tracked. domains_blacklist is an array of strings.
    • sends custom_event with the given payload

    • sends contact_form_submit event with the given payload

    • sends web_banner_click event with the given destination URL for banner specified by bannerId

  • track(“web_banner_impression”, null, bannerId)
    • sends web_banner_impression event for banner specified by bannerId

MeiroEvents.updateStorageConsents({ statistics: boolean })

The method enables users to update the consent configuration at a later time when the customer updates their consent.