mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
chore: Execute campaigns based on matching URL (#2254)
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user