@outlit/browser 1.4.3 → 1.4.5
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/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +69 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -6
- package/dist/index.mjs.map +1 -1
- package/dist/outlit.global.js +1 -1
- package/dist/outlit.global.js.map +1 -1
- package/dist/react/index.d.mts +116 -116
- package/dist/react/index.d.ts +116 -116
- package/dist/react/index.js +72 -5
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +75 -7
- package/dist/react/index.mjs.map +1 -1
- package/dist/{tracker-CzhtZoOC.d.mts → tracker-DlHUyaah.d.mts} +3 -5
- package/dist/{tracker-CzhtZoOC.d.ts → tracker-DlHUyaah.d.ts} +3 -5
- package/dist/vue/index.d.mts +46 -46
- package/dist/vue/index.d.ts +46 -46
- package/dist/vue/index.js +72 -5
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/index.mjs +75 -7
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +32 -18
package/dist/react/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
// src/react/hooks.ts
|
|
2
|
+
import { useCallback as useCallback2, useContext } from "react";
|
|
3
|
+
|
|
1
4
|
// src/react/provider.tsx
|
|
2
5
|
import { createContext, useCallback, useEffect, useRef, useState } from "react";
|
|
3
6
|
|
|
4
7
|
// src/tracker.ts
|
|
5
8
|
import {
|
|
6
|
-
DEFAULT_API_HOST,
|
|
7
9
|
buildBillingEvent,
|
|
8
10
|
buildCalendarEvent,
|
|
9
11
|
buildCustomEvent,
|
|
@@ -11,7 +13,9 @@ import {
|
|
|
11
13
|
buildIdentifyEvent,
|
|
12
14
|
buildIngestPayload,
|
|
13
15
|
buildPageviewEvent,
|
|
14
|
-
buildStageEvent
|
|
16
|
+
buildStageEvent,
|
|
17
|
+
DEFAULT_API_HOST,
|
|
18
|
+
validateCustomerIdentity
|
|
15
19
|
} from "@outlit/core";
|
|
16
20
|
|
|
17
21
|
// src/autocapture.ts
|
|
@@ -796,11 +800,19 @@ var Outlit = class {
|
|
|
796
800
|
console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
|
|
797
801
|
return;
|
|
798
802
|
}
|
|
803
|
+
if (!options.email && !options.userId) {
|
|
804
|
+
console.warn("[Outlit] identify requires email or userId");
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
799
807
|
if (options.email || options.userId) {
|
|
800
808
|
const hadNoUser = !this.currentUser;
|
|
801
809
|
this.currentUser = {
|
|
802
810
|
email: options.email,
|
|
803
|
-
userId: options.userId
|
|
811
|
+
userId: options.userId,
|
|
812
|
+
customerId: options.customerId,
|
|
813
|
+
customerDomain: options.customerDomain,
|
|
814
|
+
customerTraits: options.customerTraits,
|
|
815
|
+
traits: options.traits
|
|
804
816
|
};
|
|
805
817
|
if (hadNoUser) {
|
|
806
818
|
this.flushPendingStageEvents();
|
|
@@ -811,6 +823,9 @@ var Outlit = class {
|
|
|
811
823
|
referrer: document.referrer,
|
|
812
824
|
email: options.email,
|
|
813
825
|
userId: options.userId,
|
|
826
|
+
customerId: options.customerId,
|
|
827
|
+
customerDomain: options.customerDomain,
|
|
828
|
+
customerTraits: options.customerTraits,
|
|
814
829
|
traits: options.traits
|
|
815
830
|
});
|
|
816
831
|
this.enqueue(event);
|
|
@@ -852,7 +867,14 @@ var Outlit = class {
|
|
|
852
867
|
*/
|
|
853
868
|
applyUser(identity) {
|
|
854
869
|
this.currentUser = identity;
|
|
855
|
-
this.identify({
|
|
870
|
+
this.identify({
|
|
871
|
+
email: identity.email,
|
|
872
|
+
userId: identity.userId,
|
|
873
|
+
traits: identity.traits,
|
|
874
|
+
customerId: identity.customerId,
|
|
875
|
+
customerDomain: identity.customerDomain,
|
|
876
|
+
customerTraits: identity.customerTraits
|
|
877
|
+
});
|
|
856
878
|
this.flushPendingStageEvents();
|
|
857
879
|
}
|
|
858
880
|
/**
|
|
@@ -920,11 +942,23 @@ var Outlit = class {
|
|
|
920
942
|
console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
|
|
921
943
|
return;
|
|
922
944
|
}
|
|
945
|
+
try {
|
|
946
|
+
validateCustomerIdentity(
|
|
947
|
+
options.customerId,
|
|
948
|
+
options.customerDomain,
|
|
949
|
+
options.domain,
|
|
950
|
+
options.stripeCustomerId
|
|
951
|
+
);
|
|
952
|
+
} catch (error) {
|
|
953
|
+
console.warn("[Outlit]", error instanceof Error ? error.message : error);
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
923
956
|
const event = buildBillingEvent({
|
|
924
957
|
url: window.location.href,
|
|
925
958
|
referrer: document.referrer,
|
|
926
959
|
status,
|
|
927
960
|
customerId: options.customerId,
|
|
961
|
+
customerDomain: options.customerDomain,
|
|
928
962
|
stripeCustomerId: options.stripeCustomerId,
|
|
929
963
|
domain: options.domain,
|
|
930
964
|
properties: options.properties
|
|
@@ -1042,12 +1076,47 @@ var Outlit = class {
|
|
|
1042
1076
|
this.flush();
|
|
1043
1077
|
}, this.flushInterval);
|
|
1044
1078
|
}
|
|
1079
|
+
getPayloadUserIdentity() {
|
|
1080
|
+
if (!this.currentUser) {
|
|
1081
|
+
return void 0;
|
|
1082
|
+
}
|
|
1083
|
+
const { email, userId } = this.currentUser;
|
|
1084
|
+
if (!email && !userId) {
|
|
1085
|
+
return void 0;
|
|
1086
|
+
}
|
|
1087
|
+
return {
|
|
1088
|
+
...email && { email },
|
|
1089
|
+
...userId && { userId }
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
getPayloadCustomerIdentity() {
|
|
1093
|
+
if (!this.currentUser) {
|
|
1094
|
+
return void 0;
|
|
1095
|
+
}
|
|
1096
|
+
const { customerId, customerDomain } = this.currentUser;
|
|
1097
|
+
if (!customerId && !customerDomain) {
|
|
1098
|
+
return void 0;
|
|
1099
|
+
}
|
|
1100
|
+
return {
|
|
1101
|
+
...customerId && { customerId },
|
|
1102
|
+
...customerDomain && { customerDomain }
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1045
1105
|
async sendEvents(events) {
|
|
1046
1106
|
if (events.length === 0) return;
|
|
1047
1107
|
if (!this.visitorId) return;
|
|
1048
|
-
const userIdentity = this.
|
|
1108
|
+
const userIdentity = this.getPayloadUserIdentity();
|
|
1109
|
+
const customerIdentity = this.getPayloadCustomerIdentity();
|
|
1049
1110
|
const sessionId = this.sessionTracker?.getSessionId();
|
|
1050
|
-
const payload = buildIngestPayload(
|
|
1111
|
+
const payload = buildIngestPayload(
|
|
1112
|
+
this.visitorId,
|
|
1113
|
+
"client",
|
|
1114
|
+
events,
|
|
1115
|
+
userIdentity,
|
|
1116
|
+
sessionId,
|
|
1117
|
+
void 0,
|
|
1118
|
+
customerIdentity
|
|
1119
|
+
);
|
|
1051
1120
|
const url = `${this.apiHost}/api/i/v1/${this.publicKey}/events`;
|
|
1052
1121
|
try {
|
|
1053
1122
|
if (typeof navigator !== "undefined" && navigator.sendBeacon) {
|
|
@@ -1196,7 +1265,6 @@ function OutlitProvider(props) {
|
|
|
1196
1265
|
}
|
|
1197
1266
|
|
|
1198
1267
|
// src/react/hooks.ts
|
|
1199
|
-
import { useCallback as useCallback2, useContext } from "react";
|
|
1200
1268
|
function useOutlit() {
|
|
1201
1269
|
const { outlit, isInitialized, isTrackingEnabled, enableTracking, disableTracking } = useContext(OutlitContext);
|
|
1202
1270
|
const track = useCallback2(
|