@usermaven/nextjs 1.5.10-rc.110 → 1.5.10-rc.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/UsermavenContext.d.ts +1 -1
- package/lib/UsermavenProvider.d.ts +2 -2
- package/lib/client.d.ts +1 -1
- package/lib/index.es.js +222 -77
- package/lib/middlewareEnv.d.ts +3 -3
- package/lib/middlewareEnv.js +23 -17
- package/lib/usePageView.d.ts +1 -1
- package/lib/useUsermaven.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { UsermavenClient } from
|
|
3
|
-
import { PropsWithChildren } from
|
|
2
|
+
import { UsermavenClient } from '@usermaven/sdk-js';
|
|
3
|
+
import { PropsWithChildren } from 'react';
|
|
4
4
|
export interface UsermavenProviderProps {
|
|
5
5
|
client: UsermavenClient | null;
|
|
6
6
|
}
|
package/lib/client.d.ts
CHANGED
package/lib/index.es.js
CHANGED
|
@@ -42,7 +42,13 @@ const Z = {
|
|
|
42
42
|
gaHook: !1,
|
|
43
43
|
segmentHook: !1,
|
|
44
44
|
randomizeUrl: !1,
|
|
45
|
-
capture3rdPartyCookies: [
|
|
45
|
+
capture3rdPartyCookies: [
|
|
46
|
+
"_ga",
|
|
47
|
+
"_fbp",
|
|
48
|
+
"_ym_uid",
|
|
49
|
+
"ajs_user_id",
|
|
50
|
+
"ajs_anonymous_id"
|
|
51
|
+
],
|
|
46
52
|
idMethod: "cookie",
|
|
47
53
|
ipPolicy: "keep",
|
|
48
54
|
cookiePolicy: "keep",
|
|
@@ -189,7 +195,10 @@ const he = function(n) {
|
|
|
189
195
|
try {
|
|
190
196
|
return n.apply(this, e);
|
|
191
197
|
} catch (t) {
|
|
192
|
-
f().error(
|
|
198
|
+
f().error(
|
|
199
|
+
"Implementation error. Please turn on debug and contact support@usermaven.com.",
|
|
200
|
+
t
|
|
201
|
+
);
|
|
193
202
|
}
|
|
194
203
|
};
|
|
195
204
|
}, Y = function(n) {
|
|
@@ -219,10 +228,13 @@ function ge(n) {
|
|
|
219
228
|
);
|
|
220
229
|
}
|
|
221
230
|
function z(n) {
|
|
222
|
-
return typeof n != "object" || n === null ? n : Array.isArray(n) ? n.map(z) : Object.keys(n).reduce(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
231
|
+
return typeof n != "object" || n === null ? n : Array.isArray(n) ? n.map(z) : Object.keys(n).reduce(
|
|
232
|
+
(e, t) => {
|
|
233
|
+
const i = ge(t);
|
|
234
|
+
return e[i] = z(n[t]), e;
|
|
235
|
+
},
|
|
236
|
+
{}
|
|
237
|
+
);
|
|
226
238
|
}
|
|
227
239
|
function x(n) {
|
|
228
240
|
switch (typeof n.className) {
|
|
@@ -252,7 +264,15 @@ function j(n) {
|
|
|
252
264
|
function M(n) {
|
|
253
265
|
return !!n && n.nodeType === 11;
|
|
254
266
|
}
|
|
255
|
-
const C = [
|
|
267
|
+
const C = [
|
|
268
|
+
"a",
|
|
269
|
+
"button",
|
|
270
|
+
"form",
|
|
271
|
+
"input",
|
|
272
|
+
"select",
|
|
273
|
+
"textarea",
|
|
274
|
+
"label"
|
|
275
|
+
];
|
|
256
276
|
function pe(n, e) {
|
|
257
277
|
if (!n || y(n, "html") || !G(n))
|
|
258
278
|
return !1;
|
|
@@ -410,7 +430,9 @@ class _e {
|
|
|
410
430
|
return window.pageYOffset || this.documentElement.scrollTop || document.body.scrollTop || 0;
|
|
411
431
|
}
|
|
412
432
|
checkMilestones(e) {
|
|
413
|
-
this.milestones.filter(
|
|
433
|
+
this.milestones.filter(
|
|
434
|
+
(i) => e >= i
|
|
435
|
+
).forEach((i) => {
|
|
414
436
|
this.send(), this.milestones = this.milestones.filter((s) => s !== i);
|
|
415
437
|
});
|
|
416
438
|
}
|
|
@@ -435,7 +457,9 @@ const I = class I {
|
|
|
435
457
|
return;
|
|
436
458
|
}
|
|
437
459
|
if (!(document && document.body)) {
|
|
438
|
-
this.logger.debug(
|
|
460
|
+
this.logger.debug(
|
|
461
|
+
"Document not ready yet, trying again in 500 milliseconds..."
|
|
462
|
+
), setTimeout(() => this.init(), 500);
|
|
439
463
|
return;
|
|
440
464
|
}
|
|
441
465
|
this.addDomEventHandlers(), this.domHandlersAttached = !0;
|
|
@@ -509,10 +533,13 @@ const I = class I {
|
|
|
509
533
|
}
|
|
510
534
|
extractCustomPropertyValue(e) {
|
|
511
535
|
const t = [];
|
|
512
|
-
return w(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
536
|
+
return w(
|
|
537
|
+
document.querySelectorAll(e.css_selector),
|
|
538
|
+
function(i) {
|
|
539
|
+
let s;
|
|
540
|
+
["input", "select"].indexOf(i.tagName.toLowerCase()) > -1 ? s = i.value : i.textContent && (s = i.textContent), T(s) && t.push(s);
|
|
541
|
+
}
|
|
542
|
+
), t.join(", ");
|
|
516
543
|
}
|
|
517
544
|
getEventTarget(e) {
|
|
518
545
|
var t;
|
|
@@ -599,9 +626,13 @@ class Ee {
|
|
|
599
626
|
this.trackingHost = e, this.logger = i, this.config = t;
|
|
600
627
|
}
|
|
601
628
|
async send(e) {
|
|
602
|
-
const t = this.config.key, i = this.constructUrl(t), s = new Blob([JSON.stringify(e)], {
|
|
629
|
+
const t = this.config.key, i = this.constructUrl(t), s = new Blob([JSON.stringify(e)], {
|
|
630
|
+
type: "application/json"
|
|
631
|
+
});
|
|
603
632
|
if (navigator.sendBeacon(i, s))
|
|
604
|
-
this.logger.debug(
|
|
633
|
+
this.logger.debug(
|
|
634
|
+
`Successfully queued ${e.length} event(s) via Beacon API`
|
|
635
|
+
);
|
|
605
636
|
else
|
|
606
637
|
throw new Error("Failed to queue events via Beacon API");
|
|
607
638
|
}
|
|
@@ -731,7 +762,9 @@ class Ae {
|
|
|
731
762
|
class K {
|
|
732
763
|
// Default to true for server-side
|
|
733
764
|
constructor(e, t = 3, i = 1e3, s = 10, r = 1e3, o = f(), a = "default") {
|
|
734
|
-
this.transport = e, this.maxRetries = t, this.retryInterval = i, this.batchSize = s, this.batchInterval = r, this.logger = o, this.queue = [], this.processing = !1, this.batchTimeoutId = null, this.isOnline = !0, this.persistence = new te(
|
|
765
|
+
this.transport = e, this.maxRetries = t, this.retryInterval = i, this.batchSize = s, this.batchInterval = r, this.logger = o, this.queue = [], this.processing = !1, this.batchTimeoutId = null, this.isOnline = !0, this.persistence = new te(
|
|
766
|
+
`offline_queue_${a}`
|
|
767
|
+
), h() && (this.isOnline = navigator.onLine, this.loadQueueFromStorage(), this.initNetworkListeners(), this.scheduleBatch());
|
|
735
768
|
}
|
|
736
769
|
add(e) {
|
|
737
770
|
const t = { payload: e, retries: 0, timestamp: Date.now() };
|
|
@@ -745,14 +778,19 @@ class K {
|
|
|
745
778
|
}));
|
|
746
779
|
}
|
|
747
780
|
scheduleBatch() {
|
|
748
|
-
h() && (this.batchTimeoutId !== null && clearTimeout(this.batchTimeoutId), this.batchTimeoutId = window.setTimeout(
|
|
781
|
+
h() && (this.batchTimeoutId !== null && clearTimeout(this.batchTimeoutId), this.batchTimeoutId = window.setTimeout(
|
|
782
|
+
() => this.processBatch(),
|
|
783
|
+
this.batchInterval
|
|
784
|
+
));
|
|
749
785
|
}
|
|
750
786
|
async processBatch() {
|
|
751
787
|
if ((!h() || this.isOnline) && !this.processing && this.queue.length > 0) {
|
|
752
788
|
this.processing = !0;
|
|
753
789
|
const e = this.queue.splice(0, this.batchSize), t = e.map((i) => i.payload);
|
|
754
790
|
try {
|
|
755
|
-
await this.transport.send(t), this.logger.debug(
|
|
791
|
+
await this.transport.send(t), this.logger.debug(
|
|
792
|
+
`Successfully sent batch of ${e.length} payloads`
|
|
793
|
+
), h() && this.saveQueueToStorage();
|
|
756
794
|
} catch (i) {
|
|
757
795
|
this.logger.error("Failed to send batch", i), await this.handleBatchFailure(e);
|
|
758
796
|
}
|
|
@@ -762,7 +800,10 @@ class K {
|
|
|
762
800
|
}
|
|
763
801
|
async handleBatchFailure(e) {
|
|
764
802
|
for (const t of e)
|
|
765
|
-
t.retries < this.maxRetries ? (t.retries++, this.queue.unshift(t), this.logger.warn(`Retry attempt ${t.retries} for payload`)) : this.logger.error(
|
|
803
|
+
t.retries < this.maxRetries ? (t.retries++, this.queue.unshift(t), this.logger.warn(`Retry attempt ${t.retries} for payload`)) : this.logger.error(
|
|
804
|
+
"Max retries reached, discarding payload",
|
|
805
|
+
t.payload
|
|
806
|
+
);
|
|
766
807
|
h() && (this.saveQueueToStorage(), await new Promise((t) => setTimeout(t, this.retryInterval)));
|
|
767
808
|
}
|
|
768
809
|
loadQueueFromStorage() {
|
|
@@ -791,14 +832,18 @@ class Se {
|
|
|
791
832
|
}
|
|
792
833
|
click(e, t, i) {
|
|
793
834
|
const s = { x: e, y: t, timestamp: i };
|
|
794
|
-
this.clicks.push(s), this.clicks = this.clicks.filter(
|
|
835
|
+
this.clicks.push(s), this.clicks = this.clicks.filter(
|
|
836
|
+
(r) => i - r.timestamp < this.timeWindow
|
|
837
|
+
), this.clicks.length >= this.threshold && this.checkRageClick();
|
|
795
838
|
}
|
|
796
839
|
checkRageClick() {
|
|
797
840
|
const e = this.clicks[0], i = (this.clicks[this.clicks.length - 1].timestamp - e.timestamp) / 1e3;
|
|
798
841
|
this.clicks.every((r, o) => {
|
|
799
842
|
if (o === 0) return !0;
|
|
800
843
|
const a = this.clicks[o - 1];
|
|
801
|
-
return Math.sqrt(
|
|
844
|
+
return Math.sqrt(
|
|
845
|
+
Math.pow(r.x - a.x, 2) + Math.pow(r.y - a.y, 2)
|
|
846
|
+
) < this.distanceThreshold;
|
|
802
847
|
}) && this.sendRageClickEvent(i);
|
|
803
848
|
}
|
|
804
849
|
sendRageClickEvent(e) {
|
|
@@ -865,12 +910,17 @@ class A {
|
|
|
865
910
|
trackFieldChanges(e) {
|
|
866
911
|
e.querySelectorAll("input, select, textarea").forEach((i) => {
|
|
867
912
|
i.addEventListener("change", (s) => {
|
|
868
|
-
const r = this._getFieldProps(
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
913
|
+
const r = this._getFieldProps(
|
|
914
|
+
s.target
|
|
915
|
+
);
|
|
916
|
+
this.instance.track(
|
|
917
|
+
"$form_field_change",
|
|
918
|
+
V({
|
|
919
|
+
form_id: e.id,
|
|
920
|
+
form_name: e.name || "",
|
|
921
|
+
field: r
|
|
922
|
+
})
|
|
923
|
+
);
|
|
874
924
|
});
|
|
875
925
|
});
|
|
876
926
|
}
|
|
@@ -886,11 +936,17 @@ class A {
|
|
|
886
936
|
form_class: e.className,
|
|
887
937
|
form_attributes: this._getElementAttributes(e),
|
|
888
938
|
fields: []
|
|
889
|
-
}, i = e.querySelectorAll(
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
939
|
+
}, i = e.querySelectorAll(
|
|
940
|
+
"input, select, textarea"
|
|
941
|
+
);
|
|
942
|
+
return Array.from(i).filter(
|
|
943
|
+
(r) => !r.classList.contains("um-no-capture")
|
|
944
|
+
).forEach(
|
|
945
|
+
(r) => {
|
|
946
|
+
const o = this._getFieldProps(r);
|
|
947
|
+
t.fields.push(o);
|
|
948
|
+
}
|
|
949
|
+
), t;
|
|
894
950
|
}
|
|
895
951
|
_getFieldProps(e) {
|
|
896
952
|
const t = Object.keys(e.dataset).length ? this._convertDOMStringMapToObject(e.dataset) : void 0, i = this.getSafeText(e);
|
|
@@ -981,14 +1037,20 @@ class N {
|
|
|
981
1037
|
// Reduced interval to .2 second
|
|
982
1038
|
this.logger,
|
|
983
1039
|
this.namespace
|
|
984
|
-
), h() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(
|
|
1040
|
+
), h() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(
|
|
1041
|
+
`Usermaven client initialized for namespace: ${this.namespace}`
|
|
1042
|
+
);
|
|
985
1043
|
}
|
|
986
1044
|
initializeBrowserFeatures() {
|
|
987
1045
|
if (this.cookieManager = new se(this.config.cookieDomain), this.config.autocapture && H.enabledForProject(this.config.key) && !this.config.disableAutocaptureListenerRegistration && (this.autoCapture = new H(this, this.config, this.logger), this.autoCapture.init()), this.config.formTracking) {
|
|
988
1046
|
const e = this.config.formTracking === !0 ? "all" : this.config.formTracking;
|
|
989
|
-
this.formTracking = A.getInstance(
|
|
990
|
-
|
|
991
|
-
|
|
1047
|
+
this.formTracking = A.getInstance(
|
|
1048
|
+
this,
|
|
1049
|
+
e || "none",
|
|
1050
|
+
{
|
|
1051
|
+
trackFieldChanges: !1
|
|
1052
|
+
}
|
|
1053
|
+
);
|
|
992
1054
|
}
|
|
993
1055
|
this.config.autoPageview && (this.pageviewTracking = new be(this)), this.config.crossDomainLinking && this.manageCrossDomainLinking(), this.config.rageClick && (this.rageClick = new Se(this)), this.setupPageLeaveTracking();
|
|
994
1056
|
}
|
|
@@ -1014,7 +1076,9 @@ class N {
|
|
|
1014
1076
|
// Reduced interval to .25 second
|
|
1015
1077
|
this.logger,
|
|
1016
1078
|
this.namespace
|
|
1017
|
-
), h() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(
|
|
1079
|
+
), h() && this.initializeBrowserFeatures(), this.anonymousId = this.getOrCreateAnonymousId(), this.logger.info(
|
|
1080
|
+
`Usermaven client reinitialized for namespace: ${this.namespace}`
|
|
1081
|
+
);
|
|
1018
1082
|
}
|
|
1019
1083
|
manageCrossDomainLinking() {
|
|
1020
1084
|
if (!this.config.crossDomainLinking || !this.config.domains)
|
|
@@ -1044,17 +1108,36 @@ class N {
|
|
|
1044
1108
|
return new Ce(e.trackingHost || t, e);
|
|
1045
1109
|
const i = "XMLHttpRequest" in window, s = typeof fetch < "u", r = typeof navigator < "u" && "sendBeacon" in navigator;
|
|
1046
1110
|
if (e.useBeaconApi && r)
|
|
1047
|
-
return new Ee(
|
|
1111
|
+
return new Ee(
|
|
1112
|
+
e.trackingHost || t,
|
|
1113
|
+
e,
|
|
1114
|
+
this.logger
|
|
1115
|
+
);
|
|
1048
1116
|
if (e.forceUseFetch && s)
|
|
1049
|
-
return new W(
|
|
1117
|
+
return new W(
|
|
1118
|
+
e.trackingHost || t,
|
|
1119
|
+
e,
|
|
1120
|
+
this.logger
|
|
1121
|
+
);
|
|
1050
1122
|
if (i)
|
|
1051
|
-
return new Pe(
|
|
1123
|
+
return new Pe(
|
|
1124
|
+
e.trackingHost || t,
|
|
1125
|
+
e,
|
|
1126
|
+
this.logger
|
|
1127
|
+
);
|
|
1052
1128
|
if (s)
|
|
1053
|
-
return new W(
|
|
1129
|
+
return new W(
|
|
1130
|
+
e.trackingHost || t,
|
|
1131
|
+
e,
|
|
1132
|
+
this.logger
|
|
1133
|
+
);
|
|
1054
1134
|
throw new Error("No suitable transport method available");
|
|
1055
1135
|
}
|
|
1056
1136
|
initializePersistence() {
|
|
1057
|
-
return this.config.disableEventPersistence || !h() ? new Ae() : new te(
|
|
1137
|
+
return this.config.disableEventPersistence || !h() ? new Ae() : new te(
|
|
1138
|
+
`${this.namespace}_${this.config.key}`,
|
|
1139
|
+
this.logger
|
|
1140
|
+
);
|
|
1058
1141
|
}
|
|
1059
1142
|
getOrCreateAnonymousId() {
|
|
1060
1143
|
var i, s;
|
|
@@ -1071,7 +1154,13 @@ class N {
|
|
|
1071
1154
|
}
|
|
1072
1155
|
t || (t = R());
|
|
1073
1156
|
const r = 365 * 10;
|
|
1074
|
-
(s = this.cookieManager) == null || s.set(
|
|
1157
|
+
(s = this.cookieManager) == null || s.set(
|
|
1158
|
+
e,
|
|
1159
|
+
t,
|
|
1160
|
+
r,
|
|
1161
|
+
document.location.protocol !== "http:",
|
|
1162
|
+
!1
|
|
1163
|
+
);
|
|
1075
1164
|
}
|
|
1076
1165
|
return t;
|
|
1077
1166
|
}
|
|
@@ -1097,7 +1186,9 @@ class N {
|
|
|
1097
1186
|
}
|
|
1098
1187
|
lead(e, t = !1) {
|
|
1099
1188
|
if (!P(e))
|
|
1100
|
-
throw new Error(
|
|
1189
|
+
throw new Error(
|
|
1190
|
+
"Lead payload must be a non-null object and not an array"
|
|
1191
|
+
);
|
|
1101
1192
|
const i = e.email;
|
|
1102
1193
|
if (!L(i)) {
|
|
1103
1194
|
this.logger.error("Lead event requires a valid email attribute");
|
|
@@ -1118,7 +1209,9 @@ class N {
|
|
|
1118
1209
|
if (!L(e))
|
|
1119
1210
|
throw new Error("Event name must be a string");
|
|
1120
1211
|
if (t !== void 0 && (typeof t != "object" || t === null || Array.isArray(t)))
|
|
1121
|
-
throw new Error(
|
|
1212
|
+
throw new Error(
|
|
1213
|
+
"Event payload must be a non-null object and not an array"
|
|
1214
|
+
);
|
|
1122
1215
|
const r = this.createEventPayload(e, t);
|
|
1123
1216
|
try {
|
|
1124
1217
|
if (i) {
|
|
@@ -1139,7 +1232,9 @@ class N {
|
|
|
1139
1232
|
if (!P(e))
|
|
1140
1233
|
throw new Error("Company properties must be an object");
|
|
1141
1234
|
if (!e.id || !e.name || !e.created_at)
|
|
1142
|
-
throw new Error(
|
|
1235
|
+
throw new Error(
|
|
1236
|
+
"Company properties must include id, name, and created_at"
|
|
1237
|
+
);
|
|
1143
1238
|
this.persistence.set("companyProps", e), t || await this.track("group", e), this.logger.info("Company identified:", e);
|
|
1144
1239
|
}
|
|
1145
1240
|
createEventPayload(e, t) {
|
|
@@ -1164,7 +1259,9 @@ class N {
|
|
|
1164
1259
|
...a
|
|
1165
1260
|
};
|
|
1166
1261
|
if (e === "$autocapture") {
|
|
1167
|
-
const d = this.processAutocaptureAttributes(
|
|
1262
|
+
const d = this.processAutocaptureAttributes(
|
|
1263
|
+
t || {}
|
|
1264
|
+
);
|
|
1168
1265
|
c.autocapture_attributes = d;
|
|
1169
1266
|
} else e !== "user_identify" && e !== "group" && (Array.isArray(this.config.propertyBlacklist) && this.config.propertyBlacklist.forEach((d) => {
|
|
1170
1267
|
delete l[d];
|
|
@@ -1174,7 +1271,15 @@ class N {
|
|
|
1174
1271
|
processAutocaptureAttributes(e) {
|
|
1175
1272
|
let t = {};
|
|
1176
1273
|
const i = e.$elements || [];
|
|
1177
|
-
return i.length && (t = { ...i[0] }), t.el_text = t.$el_text || "", t.event_type = e.$event_type || "", [
|
|
1274
|
+
return i.length && (t = { ...i[0] }), t.el_text = t.$el_text || "", t.event_type = e.$event_type || "", [
|
|
1275
|
+
"$ce_version",
|
|
1276
|
+
"$event_type",
|
|
1277
|
+
"$initial_referrer",
|
|
1278
|
+
"$initial_referring_domain",
|
|
1279
|
+
"$referrer",
|
|
1280
|
+
"$referring_domain",
|
|
1281
|
+
"$elements"
|
|
1282
|
+
].forEach((s) => {
|
|
1178
1283
|
delete t[s];
|
|
1179
1284
|
}), delete t.$el_text, delete t.nth_child, delete t.nth_of_type, t;
|
|
1180
1285
|
}
|
|
@@ -1192,16 +1297,28 @@ class N {
|
|
|
1192
1297
|
}
|
|
1193
1298
|
getUtmParams() {
|
|
1194
1299
|
const e = {}, t = we(window.location.search);
|
|
1195
|
-
return [
|
|
1300
|
+
return [
|
|
1301
|
+
"utm_source",
|
|
1302
|
+
"utm_medium",
|
|
1303
|
+
"utm_campaign",
|
|
1304
|
+
"utm_term",
|
|
1305
|
+
"utm_content"
|
|
1306
|
+
].forEach((s) => {
|
|
1196
1307
|
t[s] && (e[s.replace("utm_", "")] = t[s]);
|
|
1197
1308
|
}), e;
|
|
1198
1309
|
}
|
|
1199
1310
|
pageview() {
|
|
1200
|
-
h() ? this.track(
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1311
|
+
h() ? this.track(
|
|
1312
|
+
"pageview",
|
|
1313
|
+
{
|
|
1314
|
+
url: window.location.href,
|
|
1315
|
+
referrer: document.referrer,
|
|
1316
|
+
title: document.title
|
|
1317
|
+
},
|
|
1318
|
+
!0
|
|
1319
|
+
) : this.logger.warn(
|
|
1320
|
+
"Pageview tracking is not available in server-side environments"
|
|
1321
|
+
);
|
|
1205
1322
|
}
|
|
1206
1323
|
setupPageLeaveTracking() {
|
|
1207
1324
|
if (!h()) return;
|
|
@@ -1236,7 +1353,10 @@ class N {
|
|
|
1236
1353
|
const t = this.config.cookieName || `__eventn_id_${this.config.key}`;
|
|
1237
1354
|
this.cookieManager.delete(t), this.anonymousId = this.getOrCreateAnonymousId();
|
|
1238
1355
|
}
|
|
1239
|
-
this.logger.info("core state reset", {
|
|
1356
|
+
this.logger.info("core state reset", {
|
|
1357
|
+
resetAnonId: e,
|
|
1358
|
+
namespace: this.namespace
|
|
1359
|
+
});
|
|
1240
1360
|
}
|
|
1241
1361
|
set(e, t) {
|
|
1242
1362
|
if (!P(e))
|
|
@@ -1269,7 +1389,10 @@ class N {
|
|
|
1269
1389
|
let r = this.persistence.get("global_props") || {};
|
|
1270
1390
|
delete r[e], this.persistence.set("global_props", r);
|
|
1271
1391
|
}
|
|
1272
|
-
s && this.persistence.save(), this.logger.debug(
|
|
1392
|
+
s && this.persistence.save(), this.logger.debug(
|
|
1393
|
+
`Property unset: ${e}`,
|
|
1394
|
+
`Event type: ${i || "global"}`
|
|
1395
|
+
);
|
|
1273
1396
|
}
|
|
1274
1397
|
}
|
|
1275
1398
|
function ie() {
|
|
@@ -1280,13 +1403,18 @@ function Te() {
|
|
|
1280
1403
|
}
|
|
1281
1404
|
const $e = "__USERMAVEN_AUTOCAPTURE_INITIALIZED__";
|
|
1282
1405
|
function O(n) {
|
|
1283
|
-
const e = JSON.parse(JSON.stringify(n)), t = z(e), i = {
|
|
1406
|
+
const e = JSON.parse(JSON.stringify(n)), t = z(e), i = {
|
|
1407
|
+
...Z,
|
|
1408
|
+
...t
|
|
1409
|
+
};
|
|
1284
1410
|
if (!i.key)
|
|
1285
1411
|
throw new Error("API key is required!");
|
|
1286
1412
|
if (!i.trackingHost)
|
|
1287
1413
|
throw new Error("Tracking host is required!");
|
|
1288
1414
|
const s = i.key || "", r = `${$e}${s}`;
|
|
1289
|
-
return h() && i.autocapture && window[r] && (console.warn(
|
|
1415
|
+
return h() && i.autocapture && window[r] && (console.warn(
|
|
1416
|
+
"Usermaven: Autocapture already initialized in another instance, skipping duplicate initialization."
|
|
1417
|
+
), i.disableAutocaptureListenerRegistration = !0), h() && i.autocapture && !i.disableAutocaptureListenerRegistration && (window[r] = !0), new N(i);
|
|
1290
1418
|
}
|
|
1291
1419
|
function xe(n) {
|
|
1292
1420
|
var s;
|
|
@@ -1310,7 +1438,10 @@ function xe(n) {
|
|
|
1310
1438
|
minSendTimeout: parseInt(n.getAttribute("data-min-send-timeout") || "", 10) || void 0,
|
|
1311
1439
|
maxSendTimeout: parseInt(n.getAttribute("data-max-send-timeout") || "", 10) || void 0,
|
|
1312
1440
|
maxSendAttempts: parseInt(n.getAttribute("data-max-send-attempts") || "", 10) || void 0,
|
|
1313
|
-
propertiesStringMaxLength: parseInt(
|
|
1441
|
+
propertiesStringMaxLength: parseInt(
|
|
1442
|
+
n.getAttribute("data-properties-string-max-length") || "",
|
|
1443
|
+
10
|
|
1444
|
+
) || null,
|
|
1314
1445
|
propertyBlacklist: ((s = n.getAttribute("data-property-blacklist")) == null ? void 0 : s.split(",")) || void 0,
|
|
1315
1446
|
exclude: n.getAttribute("data-exclude") || void 0,
|
|
1316
1447
|
namespace: n.getAttribute("data-namespace") || void 0,
|
|
@@ -1365,7 +1496,15 @@ function He(n, e) {
|
|
|
1365
1496
|
return e[g].apply(e, u.slice(1));
|
|
1366
1497
|
console.error(`Method ${g} not found on UsermavenClient`);
|
|
1367
1498
|
}
|
|
1368
|
-
const l = ["id", "group", "reset"], c = [
|
|
1499
|
+
const l = ["id", "group", "reset"], c = [
|
|
1500
|
+
"track",
|
|
1501
|
+
"lead",
|
|
1502
|
+
"pageview",
|
|
1503
|
+
"set",
|
|
1504
|
+
"unset",
|
|
1505
|
+
"rawTrack",
|
|
1506
|
+
"setUserId"
|
|
1507
|
+
];
|
|
1369
1508
|
[...l, ...c].forEach((u) => {
|
|
1370
1509
|
a[u] = function(...g) {
|
|
1371
1510
|
if (!t) {
|
|
@@ -1732,9 +1871,9 @@ function hasSetMethod(cookies) {
|
|
|
1732
1871
|
}
|
|
1733
1872
|
function middlewareEnv(req, res, opts = {}) {
|
|
1734
1873
|
return {
|
|
1735
|
-
getAnonymousId({ name, domain }) {
|
|
1874
|
+
getAnonymousId({ name, domain, }) {
|
|
1736
1875
|
if (opts === null || opts === void 0 ? void 0 : opts.disableCookies) {
|
|
1737
|
-
return
|
|
1876
|
+
return '';
|
|
1738
1877
|
}
|
|
1739
1878
|
let cookie;
|
|
1740
1879
|
if (hasGetMethod(req.cookies)) {
|
|
@@ -1750,7 +1889,7 @@ function middlewareEnv(req, res, opts = {}) {
|
|
|
1750
1889
|
const cookieOpts = {
|
|
1751
1890
|
maxAge: 31622400 * 10,
|
|
1752
1891
|
httpOnly: false,
|
|
1753
|
-
path:
|
|
1892
|
+
path: '/',
|
|
1754
1893
|
};
|
|
1755
1894
|
if (domain) {
|
|
1756
1895
|
cookieOpts.domain = domain;
|
|
@@ -1762,36 +1901,42 @@ function middlewareEnv(req, res, opts = {}) {
|
|
|
1762
1901
|
value: newId,
|
|
1763
1902
|
maxAge: cookieOpts.maxAge,
|
|
1764
1903
|
domain: cookieOpts.domain,
|
|
1765
|
-
httpOnly: cookieOpts.httpOnly
|
|
1904
|
+
httpOnly: cookieOpts.httpOnly,
|
|
1766
1905
|
});
|
|
1767
1906
|
}
|
|
1768
1907
|
else {
|
|
1769
|
-
res.headers.set(
|
|
1908
|
+
res.headers.set('Set-Cookie', serialize_1(name, newId, cookieOpts));
|
|
1770
1909
|
}
|
|
1771
1910
|
return newId;
|
|
1772
1911
|
},
|
|
1773
1912
|
getSourceIp() {
|
|
1774
|
-
let ip = req.headers.get(
|
|
1775
|
-
|
|
1913
|
+
let ip = req.headers.get('x-forwarded-for') ||
|
|
1914
|
+
req.headers.get('x-real-ip') ||
|
|
1915
|
+
'';
|
|
1916
|
+
return ip && ip.split(',')[0].trim();
|
|
1776
1917
|
},
|
|
1777
1918
|
describeClient() {
|
|
1778
1919
|
var _a;
|
|
1779
|
-
const requestHost = req.headers.get(
|
|
1780
|
-
|
|
1920
|
+
const requestHost = req.headers.get('x-forwarded-host') ||
|
|
1921
|
+
req.headers.get('host') ||
|
|
1922
|
+
req.nextUrl.hostname;
|
|
1923
|
+
const proto = req.headers.get('x-forwarded-proto') ||
|
|
1924
|
+
((_a = req.nextUrl.protocol) === null || _a === void 0 ? void 0 : _a.replace(':', ''));
|
|
1781
1925
|
let query = req.nextUrl.search;
|
|
1782
1926
|
let path = req.nextUrl.pathname;
|
|
1783
1927
|
return {
|
|
1784
|
-
doc_encoding:
|
|
1928
|
+
doc_encoding: '',
|
|
1785
1929
|
doc_host: requestHost,
|
|
1786
1930
|
doc_path: req.url,
|
|
1787
1931
|
doc_search: query,
|
|
1788
|
-
page_title:
|
|
1789
|
-
referer: req.headers.get(
|
|
1790
|
-
screen_resolution:
|
|
1791
|
-
url: `${proto}://${requestHost}${path ||
|
|
1792
|
-
user_agent: req.headers.get(
|
|
1793
|
-
user_language: req.headers.get(
|
|
1794
|
-
|
|
1932
|
+
page_title: '',
|
|
1933
|
+
referer: req.headers.get('referrer'),
|
|
1934
|
+
screen_resolution: '',
|
|
1935
|
+
url: `${proto}://${requestHost}${path || ''}${query || ''}`,
|
|
1936
|
+
user_agent: req.headers.get('user-agent'),
|
|
1937
|
+
user_language: req.headers.get('accept-language') &&
|
|
1938
|
+
req.headers.get('accept-language').split(',')[0],
|
|
1939
|
+
vp_size: '',
|
|
1795
1940
|
};
|
|
1796
1941
|
},
|
|
1797
1942
|
};
|
package/lib/middlewareEnv.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from
|
|
2
|
-
import { ClientProperties } from
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { ClientProperties } from '@usermaven/sdk-js';
|
|
3
3
|
declare function middlewareEnv(req: NextRequest, res: NextResponse, opts?: {
|
|
4
4
|
disableCookies?: boolean;
|
|
5
5
|
}): {
|
|
6
|
-
getAnonymousId({ name, domain }: {
|
|
6
|
+
getAnonymousId({ name, domain, }: {
|
|
7
7
|
name: string;
|
|
8
8
|
domain?: string;
|
|
9
9
|
}): string;
|
package/lib/middlewareEnv.js
CHANGED
|
@@ -9,9 +9,9 @@ function hasSetMethod(cookies) {
|
|
|
9
9
|
}
|
|
10
10
|
function middlewareEnv(req, res, opts = {}) {
|
|
11
11
|
return {
|
|
12
|
-
getAnonymousId({ name, domain }) {
|
|
12
|
+
getAnonymousId({ name, domain, }) {
|
|
13
13
|
if (opts === null || opts === void 0 ? void 0 : opts.disableCookies) {
|
|
14
|
-
return
|
|
14
|
+
return '';
|
|
15
15
|
}
|
|
16
16
|
let cookie;
|
|
17
17
|
if (hasGetMethod(req.cookies)) {
|
|
@@ -27,7 +27,7 @@ function middlewareEnv(req, res, opts = {}) {
|
|
|
27
27
|
const cookieOpts = {
|
|
28
28
|
maxAge: 31622400 * 10,
|
|
29
29
|
httpOnly: false,
|
|
30
|
-
path:
|
|
30
|
+
path: '/',
|
|
31
31
|
};
|
|
32
32
|
if (domain) {
|
|
33
33
|
cookieOpts.domain = domain;
|
|
@@ -39,36 +39,42 @@ function middlewareEnv(req, res, opts = {}) {
|
|
|
39
39
|
value: newId,
|
|
40
40
|
maxAge: cookieOpts.maxAge,
|
|
41
41
|
domain: cookieOpts.domain,
|
|
42
|
-
httpOnly: cookieOpts.httpOnly
|
|
42
|
+
httpOnly: cookieOpts.httpOnly,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
res.headers.set(
|
|
46
|
+
res.headers.set('Set-Cookie', (0, cookie_1.serialize)(name, newId, cookieOpts));
|
|
47
47
|
}
|
|
48
48
|
return newId;
|
|
49
49
|
},
|
|
50
50
|
getSourceIp() {
|
|
51
|
-
let ip = req.headers.get(
|
|
52
|
-
|
|
51
|
+
let ip = req.headers.get('x-forwarded-for') ||
|
|
52
|
+
req.headers.get('x-real-ip') ||
|
|
53
|
+
'';
|
|
54
|
+
return ip && ip.split(',')[0].trim();
|
|
53
55
|
},
|
|
54
56
|
describeClient() {
|
|
55
57
|
var _a;
|
|
56
|
-
const requestHost = req.headers.get(
|
|
57
|
-
|
|
58
|
+
const requestHost = req.headers.get('x-forwarded-host') ||
|
|
59
|
+
req.headers.get('host') ||
|
|
60
|
+
req.nextUrl.hostname;
|
|
61
|
+
const proto = req.headers.get('x-forwarded-proto') ||
|
|
62
|
+
((_a = req.nextUrl.protocol) === null || _a === void 0 ? void 0 : _a.replace(':', ''));
|
|
58
63
|
let query = req.nextUrl.search;
|
|
59
64
|
let path = req.nextUrl.pathname;
|
|
60
65
|
return {
|
|
61
|
-
doc_encoding:
|
|
66
|
+
doc_encoding: '',
|
|
62
67
|
doc_host: requestHost,
|
|
63
68
|
doc_path: req.url,
|
|
64
69
|
doc_search: query,
|
|
65
|
-
page_title:
|
|
66
|
-
referer: req.headers.get(
|
|
67
|
-
screen_resolution:
|
|
68
|
-
url: `${proto}://${requestHost}${path ||
|
|
69
|
-
user_agent: req.headers.get(
|
|
70
|
-
user_language: req.headers.get(
|
|
71
|
-
|
|
70
|
+
page_title: '',
|
|
71
|
+
referer: req.headers.get('referrer'),
|
|
72
|
+
screen_resolution: '',
|
|
73
|
+
url: `${proto}://${requestHost}${path || ''}${query || ''}`,
|
|
74
|
+
user_agent: req.headers.get('user-agent'),
|
|
75
|
+
user_language: req.headers.get('accept-language') &&
|
|
76
|
+
req.headers.get('accept-language').split(',')[0],
|
|
77
|
+
vp_size: '',
|
|
72
78
|
};
|
|
73
79
|
},
|
|
74
80
|
};
|
package/lib/usePageView.d.ts
CHANGED
package/lib/useUsermaven.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usermaven/nextjs",
|
|
3
|
-
"version": "1.5.10-rc.
|
|
3
|
+
"version": "1.5.10-rc.111",
|
|
4
4
|
"description": "Usermaven JavaScript SDK for NextJS",
|
|
5
5
|
"author": "Usermaven <hello@usermaven.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@usermaven/sdk-js": "1.5.10-rc.
|
|
21
|
+
"@usermaven/sdk-js": "1.5.10-rc.111",
|
|
22
22
|
"cookie": "^0.5.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|