Pop-up and native banners: instructions for developers
Prerequisites To work with 1. Meiro Events must be implemented. 2. Meiro Events API connection must be set in the Administration/ 3. 4. For |
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”).
DOM containers for embedded web banners
To make embedded web banners displayed you have to place some container (DOM element) with a unique id into your website page,
eg. <div id=”meiro-embedded-banner-sidebar”></div>
so a user can fill this id in Meiro Business Explorer (embedded web banners tab) as a web banner position. There can be multiple web banner containers at different places on a single page.
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.closePopUpWebBanner(): void |
Closes the current pop up banner. Can be used if you implement your own close button. |
MeiroEvents.getWebBannerHttpResponses(bannerId: string): Array<{ url: string, data: any }> |
If the conditions for the banner Remember: 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. Use the |
MeiroEvents.goToWebBannerUrl(url: string, bannerId): void |
Transitions user to the giver URL (if the meiro:bannerclick DOM event is not prevented) and tracks the web_banner_click event in Meiro Events. It also emits the meiro:bannerclick DOM event. |
Get banner id from within the HTML banner code
SDK no longer supports obtaining banner id by its own interface because it’s no longer possible after the implementation of embedded web banners. There can be several banners at the same time on the pagepage, and it’s not obvious which one you may be asking for.
From now onon, use the window.frameElement.getAttribute('data-bannerid')
method to get banner id.
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 For Similarly, for |
DateTime / Relative DateTime |
The value is passed as an argument to the JavaScript Date class constructor before comparing it with the provided value. If the result of the conversion is an invalid date, the condition will always fail.
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 a |
Number |
The value is converted to the JavaScript number type before comparison. |
String |
The value is converted to the JavaScript string type before comparison. |
Display pop pop-up web banner on any user interaction by idID
MeiroEvents.showPopUpWebBanner("banner-id-here");
ID will be: eacf4043-ec65-4c30-939e-87c2ce19ac40
Remember: If a web banner has set the HTTP request trigger condition, the method getWebBannerHttpResponses
will return an empty array as the request will not be executed. Keep it in mind when using response data in the banner.
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 structurestructure, 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"
}