Web banners: instructions for developers
General
The evaluation of conditions for displaying banners and the insertion of the banner into the page (if any) happens during the MeiroEvents.track(“pageview”)
function call.
If your website is a single-page application and you call this function manually, and if there are any cookie/local storage/GTM conditions, make sure that the relevant cookies etc. are set before this tracking call.
The element containing the banner has a z-index value set to 1000000
(1 million). This includes the overlay (for banners with the position set to “middle”).
HTML banners
If you want to access the window object of the main page from within the banner HTML code, you can access it under window.parent
, and you can access the Meiro Events SDK under window.parent.MeiroEvents
.
The SDK exposes several methods that can be used inside the HTML banner code:
MeiroEvents.closeWebBanner(): void
Closes the current banner. Can be used if you implement your own close button.
MeiroEvents.getWebBannerId(): string
Returns the id of the current banner. Can be used for tracking custom events inside the banner or to retrieve stored HTTP responses.
MeiroEvents.getWebBannerHttpResponses(bannerId: string | undefined): Array<{ url: string, data: any }>
If the conditions for the banner included any HTTP request conditions, the responses will be stored in an array of objects. Each object will contain a url
property with the URL to which the request was made, and a data
property containing the parsed body of the response. Note: the order of the responses in the array is not guaranteed to be the same as the order of the conditions in the condition builder! Examine the URL to differentiate between multiple HTTP conditions. If the bannerId
argument is not specified, the responses of the currently shown banner will be returned.
You can also track events as usual via MeiroEvents.track(...)
from inside the banner.
Cookie, local storage, and Google Tag Manager data type handling
The values retrieved from cookies/storage/GTM are handled in the following way for the purposes of condition evaluation:
Boolean |
The operators are “yes” and “no”.
|
DateTime / Relative DateTime |
The value is passed as an argument to the JavaScript
Values retrieved from cookies and local storage are always retrieved as strings. If you store a JavaScript UNIX timestamp (number of milliseconds), this number will be retrieved as string and parsing to |
Number | The value is converted to the JavaScript number type before comparison. |
String | The value is converted to the JavaScript string type before comparison. |
Capturing custom DOM events
The SDK triggers DOM events for each banner action, namely show, click (image banner only) and close. The events can be captured by implementing event listeners into your code:
document.addEventListener("meiro:bannershow", (event) => {...do whatever you want...})
Event names: meiro:bannershow
, meiro:bannerclick
, meiro:bannerclose
Each event holds banner data in the following structure accessible under event.detail
property:
{
type: "show" | "click" | "close",
bannerId: "some-banner-id",
bannerName: "Some banner name",
// url is present only in the meiro:bannerclick event
url: "https://www.example.com"
}