Comparing version 2.1.2 to 2.2.0
@@ -16,3 +16,3 @@ declare global { | ||
private apiSecretKey; | ||
private options; | ||
private options?; | ||
private userId; | ||
@@ -26,7 +26,8 @@ private sessionId; | ||
private viewportSize; | ||
constructor(propertyId: string, apiSecretKey: string, options?: { | ||
constructor(propertyId: string, apiSecretKey: string, options?: Partial<{ | ||
useMeasurementProtocolWhen: () => boolean; | ||
gtagConfig?: Record<string, unknown>; | ||
onPageView?: (pagePath: string) => void; | ||
}); | ||
gtagConfig: Record<string, unknown>; | ||
onPageView: (pagePath: string) => void; | ||
debug: boolean; | ||
}>); | ||
getVisitorID(): Promise<string>; | ||
@@ -33,0 +34,0 @@ private isMeasurementProtocolRequired; |
@@ -26,5 +26,3 @@ var zga4 = (() => { | ||
var AdaptiveAnalytics = class { | ||
constructor(propertyId, apiSecretKey, options = { | ||
useMeasurementProtocolWhen: () => ["http:", "https:"].indexOf(window.location.protocol) === -1 | ||
}) { | ||
constructor(propertyId, apiSecretKey, options) { | ||
this.propertyId = propertyId; | ||
@@ -45,2 +43,3 @@ this.apiSecretKey = apiSecretKey; | ||
setTimeout(() => { | ||
var _a; | ||
this.trackEvent("page_view", { | ||
@@ -51,3 +50,3 @@ page_path: pathname, | ||
}); | ||
if (this.options.onPageView) { | ||
if ((_a = this.options) == null ? void 0 : _a.onPageView) { | ||
this.options.onPageView(pathname); | ||
@@ -87,3 +86,3 @@ } | ||
window.gtag("js", /* @__PURE__ */ new Date()); | ||
window.gtag("config", propertyId, options.gtagConfig); | ||
window.gtag("config", propertyId, options == null ? void 0 : options.gtagConfig); | ||
} | ||
@@ -119,3 +118,7 @@ } | ||
isMeasurementProtocolRequired() { | ||
return this.options.useMeasurementProtocolWhen(); | ||
var _a; | ||
if ((_a = this.options) == null ? void 0 : _a.useMeasurementProtocolWhen) { | ||
return this.options.useMeasurementProtocolWhen(); | ||
} | ||
return true; | ||
} | ||
@@ -141,6 +144,7 @@ async loadScript(url) { | ||
collect = () => { | ||
var _a; | ||
if (this.userId) { | ||
if (this.eventQueue.length) { | ||
fetch( | ||
`https://www.google-analytics.com/mp/collect?measurement_id=${this.propertyId}&api_secret=${this.apiSecretKey}`, | ||
`https://www.google-analytics.com/${((_a = this.options) == null ? void 0 : _a.debug) ? "debug/" : ""}mp/collect?measurement_id=${this.propertyId}&api_secret=${this.apiSecretKey}`, | ||
{ | ||
@@ -147,0 +151,0 @@ method: "POST", |
@@ -26,5 +26,3 @@ var __defProp = Object.defineProperty; | ||
var AdaptiveAnalytics = class { | ||
constructor(propertyId, apiSecretKey, options = { | ||
useMeasurementProtocolWhen: () => ["http:", "https:"].indexOf(window.location.protocol) === -1 | ||
}) { | ||
constructor(propertyId, apiSecretKey, options) { | ||
this.propertyId = propertyId; | ||
@@ -45,2 +43,3 @@ this.apiSecretKey = apiSecretKey; | ||
setTimeout(() => { | ||
var _a; | ||
this.trackEvent("page_view", { | ||
@@ -51,3 +50,3 @@ page_path: pathname, | ||
}); | ||
if (this.options.onPageView) { | ||
if ((_a = this.options) == null ? void 0 : _a.onPageView) { | ||
this.options.onPageView(pathname); | ||
@@ -87,3 +86,3 @@ } | ||
window.gtag("js", /* @__PURE__ */ new Date()); | ||
window.gtag("config", propertyId, options.gtagConfig); | ||
window.gtag("config", propertyId, options == null ? void 0 : options.gtagConfig); | ||
} | ||
@@ -119,3 +118,7 @@ } | ||
isMeasurementProtocolRequired() { | ||
return this.options.useMeasurementProtocolWhen(); | ||
var _a; | ||
if ((_a = this.options) == null ? void 0 : _a.useMeasurementProtocolWhen) { | ||
return this.options.useMeasurementProtocolWhen(); | ||
} | ||
return true; | ||
} | ||
@@ -141,6 +144,7 @@ async loadScript(url) { | ||
collect = () => { | ||
var _a; | ||
if (this.userId) { | ||
if (this.eventQueue.length) { | ||
fetch( | ||
`https://www.google-analytics.com/mp/collect?measurement_id=${this.propertyId}&api_secret=${this.apiSecretKey}`, | ||
`https://www.google-analytics.com/${((_a = this.options) == null ? void 0 : _a.debug) ? "debug/" : ""}mp/collect?measurement_id=${this.propertyId}&api_secret=${this.apiSecretKey}`, | ||
{ | ||
@@ -147,0 +151,0 @@ method: "POST", |
{ | ||
"name": "zmp-ga4", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Nguyễn Hồng Phát", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
22633
568