Popup JavaScript API Reference
This section is a reference list for all the Popup API functions. An explanation and some example for each are listed.
_gl.p.actionPopup()
Use this to set a custom popup as actioned, a popup is actioned when a user interacts with the popup in the way you intended, such as clicking a link or filling a form. Tell the Popup API when a user has interacted with the popup. This function also closes the popup when called.
Parameters
popupId – the id of the popup to action. This can be found near the custom HTML input when editing a custom popup.
Examples
_gl.p.actionPopup(1);
_gl.p.actionPopupAndStayOpen()
Exactly the same as _gl.p.actionPopup(), but does not close the popup when called. Use this if you want to display something else in the popup after a user has actioned it.
Parameters
popupId – the id of the popup to action. This can be found near the custom HTML input when editing a custom popup.
Examples
_gl.p.actionPopupAndStayOpen(1);
_gl.p.hidePopup()
Use this to hide a popup that is currently showing. This is best used in conjunction with _gl.p.actionPopupAndStayOpen()
.
Parameters
popupId – the id of the popup to action. This can be found near the custom HTML input when editing a custom popup.
Examples
_gl.p.hidePopup(1);
_gl.p.reload()
Use this to force the Popup script to find and render all popups again. This is best used on Single Page Applications where browsers do not navigate to new pages.
Parameters
None
Example
_gl.p.reload();
_gl.p.pushData()
Use this function to provide data to the Popup API for either content personalisation or custom targeting parameters.
Parameters
data – this can either be an object with properties group, key and value or an array of those objects.
Examples
_gl.p.pushData({ group: “content”, key: “foo”, value: “Bar” });
_gl.p.pushData([{ group: “targeting”, key: “bar”, value: “Bar” }, { group: “content”, key: “foobar”, value: “FooBar” }]);
Notes
In some cases, you might see issues where _gl is not defined or the API function you are trying to use is not defined. This is because the code you have written to call the popup api is running before the popup script can be loaded. In these situations, add some additional code, such as the below, to wait for the script to be loaded before using the popup API.
function waitFor(checkingCallback, doneCallback) {
var interval = setInterval(function() {
if(checkingCallback() !== "undefined") {
doneCallback();
clearInterval(interval);
}
}, 300);
}
// use the function defined above to wait until _gl.p is loaded before using the API
waitFor(
function() { return _gl.p },
function() {
// add code interacting with the Popup API here
}
);