chore: Execute campaigns based on matching URL (#2254)

This commit is contained in:
Muhsin Keloth
2021-05-17 21:38:35 +05:30
committed by GitHub
parent 18cea3b0ac
commit 610a7c661e
13 changed files with 242 additions and 45 deletions

View File

@@ -1,4 +1,5 @@
import { SDK_CSS } from './sdk.js';
import { IFrameHelper } from './IFrameHelper';
export const loadCSS = () => {
const css = document.createElement('style');
@@ -65,3 +66,38 @@ export const toggleClass = (elm, classes) => {
export const removeClass = (elm, classes) => {
classHelper(classes, 'remove', elm);
};
export const onLocationChange = ({ referrerURL, referrerHost }) => {
IFrameHelper.events.onLocationChange({
referrerURL,
referrerHost,
});
};
export const onLocationChangeListener = () => {
let oldHref = document.location.href;
const referrerHost = document.location.host;
const config = {
childList: true,
subtree: true,
};
onLocationChange({
referrerURL: oldHref,
referrerHost,
});
const bodyList = document.querySelector('body');
const observer = new MutationObserver(mutations => {
mutations.forEach(() => {
if (oldHref !== document.location.href) {
oldHref = document.location.href;
onLocationChange({
referrerURL: oldHref,
referrerHost,
});
}
});
});
observer.observe(bodyList, config);
};