Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "zmp-ga4", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Nguyễn Hồng Phát", |
@@ -80,8 +80,26 @@ "use strict"; | ||
window.addEventListener("beforeunload", this.collect); | ||
window.addEventListener("popstate", function () { | ||
var handleLocationChange = function () { | ||
_this.trackEvent("page_view", { | ||
page_path: location.pathname, | ||
page_params: location.search | ||
page_params: location.search, | ||
page_title: document.title | ||
}); | ||
}); | ||
}; | ||
handleLocationChange(); | ||
window.addEventListener("popstate", handleLocationChange); | ||
// Replace history.pushState to dispatch a custom event | ||
var originalPushState_1 = history.pushState; | ||
history.pushState = function () { | ||
originalPushState_1.apply(this, arguments); | ||
window.dispatchEvent(new Event("pushstate")); | ||
}; | ||
// Replace history.replaceState to dispatch a custom event | ||
var originalReplaceState_1 = history.replaceState; | ||
history.replaceState = function () { | ||
originalReplaceState_1.apply(this, arguments); | ||
window.dispatchEvent(new Event("replacestate")); | ||
}; | ||
// Add event listeners for pushstate and replacestate events | ||
window.addEventListener("pushstate", handleLocationChange); | ||
window.addEventListener("replacestate", handleLocationChange); | ||
} | ||
@@ -88,0 +106,0 @@ else { |
@@ -24,8 +24,29 @@ export class AdaptiveAnalytics { | ||
window.addEventListener("beforeunload", this.collect); | ||
window.addEventListener("popstate", () => { | ||
const handleLocationChange = () => { | ||
this.trackEvent("page_view", { | ||
page_path: location.pathname, | ||
page_params: location.search, | ||
page_title: document.title, | ||
}); | ||
}); | ||
}; | ||
handleLocationChange(); | ||
window.addEventListener("popstate", handleLocationChange); | ||
// Replace history.pushState to dispatch a custom event | ||
const originalPushState = history.pushState; | ||
history.pushState = function () { | ||
originalPushState.apply(this, arguments); | ||
window.dispatchEvent(new Event("pushstate")); | ||
}; | ||
// Replace history.replaceState to dispatch a custom event | ||
const originalReplaceState = history.replaceState; | ||
history.replaceState = function () { | ||
originalReplaceState.apply(this, arguments); | ||
window.dispatchEvent(new Event("replacestate")); | ||
}; | ||
// Add event listeners for pushstate and replacestate events | ||
window.addEventListener("pushstate", handleLocationChange); | ||
window.addEventListener("replacestate", handleLocationChange); | ||
} else { | ||
@@ -32,0 +53,0 @@ this.loadScript( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14107
296