@outlit/browser 0.4.1 → 1.0.1
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 +6 -8
- package/dist/index.d.ts +6 -8
- package/dist/index.js +52 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -50
- 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 +18 -21
- package/dist/react/index.d.ts +18 -21
- package/dist/react/index.js +87 -41
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +88 -41
- package/dist/react/index.mjs.map +1 -1
- package/dist/{tracker-DK-2gYCi.d.mts → tracker-DYFoLUE0.d.mts} +23 -40
- package/dist/{tracker-DK-2gYCi.d.ts → tracker-DYFoLUE0.d.ts} +23 -40
- package/package.json +2 -2
package/dist/react/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { createContext, useCallback, useEffect, useRef, useState } from "react";
|
|
|
4
4
|
// src/tracker.ts
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_API_HOST,
|
|
7
|
+
buildBillingEvent,
|
|
7
8
|
buildCalendarEvent,
|
|
8
9
|
buildCustomEvent,
|
|
9
10
|
buildFormEvent,
|
|
@@ -709,7 +710,7 @@ var Outlit = class {
|
|
|
709
710
|
* Links the anonymous visitor to a known user.
|
|
710
711
|
*
|
|
711
712
|
* When email or userId is provided, also sets the current user identity
|
|
712
|
-
* for stage events (activate, engaged,
|
|
713
|
+
* for stage events (activate, engaged, inactive).
|
|
713
714
|
*/
|
|
714
715
|
identify(options) {
|
|
715
716
|
if (!this.isTrackingEnabled) {
|
|
@@ -770,37 +771,22 @@ var Outlit = class {
|
|
|
770
771
|
this.identify({ email: identity.email, userId: identity.userId, traits: identity.traits });
|
|
771
772
|
}
|
|
772
773
|
/**
|
|
773
|
-
*
|
|
774
|
-
* This is typically called after a user completes onboarding or a key activation milestone.
|
|
775
|
-
* Requires the user to be identified (via setUser or identify with userId).
|
|
774
|
+
* User namespace methods for contact journey stages.
|
|
776
775
|
*/
|
|
777
|
-
|
|
778
|
-
this.
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
* Can also be computed automatically by the engagement cron.
|
|
784
|
-
*/
|
|
785
|
-
engaged(properties) {
|
|
786
|
-
this.sendStageEvent("engaged", properties);
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Mark the current user as paid.
|
|
790
|
-
* This is typically called after a successful payment/subscription.
|
|
791
|
-
* Can also be triggered by Stripe integration.
|
|
792
|
-
*/
|
|
793
|
-
paid(properties) {
|
|
794
|
-
this.sendStageEvent("paid", properties);
|
|
795
|
-
}
|
|
776
|
+
user = {
|
|
777
|
+
identify: (options) => this.identify(options),
|
|
778
|
+
activate: (properties) => this.sendStageEvent("activated", properties),
|
|
779
|
+
engaged: (properties) => this.sendStageEvent("engaged", properties),
|
|
780
|
+
inactive: (properties) => this.sendStageEvent("inactive", properties)
|
|
781
|
+
};
|
|
796
782
|
/**
|
|
797
|
-
*
|
|
798
|
-
* This is typically called when a subscription is cancelled.
|
|
799
|
-
* Can also be triggered by Stripe integration.
|
|
783
|
+
* Customer namespace methods for billing status.
|
|
800
784
|
*/
|
|
801
|
-
|
|
802
|
-
this.
|
|
803
|
-
|
|
785
|
+
customer = {
|
|
786
|
+
trialing: (options) => this.sendBillingEvent("trialing", options),
|
|
787
|
+
paid: (options) => this.sendBillingEvent("paid", options),
|
|
788
|
+
churned: (options) => this.sendBillingEvent("churned", options)
|
|
789
|
+
};
|
|
804
790
|
/**
|
|
805
791
|
* Internal method to send a stage event.
|
|
806
792
|
*/
|
|
@@ -823,6 +809,22 @@ var Outlit = class {
|
|
|
823
809
|
});
|
|
824
810
|
this.enqueue(event);
|
|
825
811
|
}
|
|
812
|
+
sendBillingEvent(status, options) {
|
|
813
|
+
if (!this.isTrackingEnabled) {
|
|
814
|
+
console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
const event = buildBillingEvent({
|
|
818
|
+
url: window.location.href,
|
|
819
|
+
referrer: document.referrer,
|
|
820
|
+
status,
|
|
821
|
+
customerId: options.customerId,
|
|
822
|
+
stripeCustomerId: options.stripeCustomerId,
|
|
823
|
+
domain: options.domain,
|
|
824
|
+
properties: options.properties
|
|
825
|
+
});
|
|
826
|
+
this.enqueue(event);
|
|
827
|
+
}
|
|
826
828
|
/**
|
|
827
829
|
* Get the current visitor ID.
|
|
828
830
|
* Returns null if tracking is not enabled.
|
|
@@ -939,8 +941,11 @@ var Outlit = class {
|
|
|
939
941
|
const blob = new Blob([JSON.stringify(payload)], { type: "application/json" });
|
|
940
942
|
const sent = navigator.sendBeacon(url, blob);
|
|
941
943
|
if (sent) return;
|
|
944
|
+
console.warn(
|
|
945
|
+
`[Outlit] sendBeacon failed for ${events.length} events, falling back to fetch`
|
|
946
|
+
);
|
|
942
947
|
}
|
|
943
|
-
await fetch(url, {
|
|
948
|
+
const response = await fetch(url, {
|
|
944
949
|
method: "POST",
|
|
945
950
|
headers: {
|
|
946
951
|
"Content-Type": "application/json"
|
|
@@ -948,8 +953,13 @@ var Outlit = class {
|
|
|
948
953
|
body: JSON.stringify(payload),
|
|
949
954
|
keepalive: true
|
|
950
955
|
});
|
|
956
|
+
if (!response.ok) {
|
|
957
|
+
console.warn(
|
|
958
|
+
`[Outlit] Server returned ${response.status} when sending ${events.length} events`
|
|
959
|
+
);
|
|
960
|
+
}
|
|
951
961
|
} catch (error) {
|
|
952
|
-
console.warn(
|
|
962
|
+
console.warn(`[Outlit] Failed to send ${events.length} events:`, error);
|
|
953
963
|
}
|
|
954
964
|
}
|
|
955
965
|
};
|
|
@@ -1057,6 +1067,16 @@ function useOutlit() {
|
|
|
1057
1067
|
},
|
|
1058
1068
|
[outlit]
|
|
1059
1069
|
);
|
|
1070
|
+
const userIdentify = useCallback2(
|
|
1071
|
+
(options) => {
|
|
1072
|
+
if (!outlit) {
|
|
1073
|
+
console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
outlit.user.identify(options);
|
|
1077
|
+
},
|
|
1078
|
+
[outlit]
|
|
1079
|
+
);
|
|
1060
1080
|
const getVisitorId = useCallback2(() => {
|
|
1061
1081
|
if (!outlit) return null;
|
|
1062
1082
|
return outlit.getVisitorId();
|
|
@@ -1084,7 +1104,7 @@ function useOutlit() {
|
|
|
1084
1104
|
console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
|
|
1085
1105
|
return;
|
|
1086
1106
|
}
|
|
1087
|
-
outlit.activate(properties);
|
|
1107
|
+
outlit.user.activate(properties);
|
|
1088
1108
|
},
|
|
1089
1109
|
[outlit]
|
|
1090
1110
|
);
|
|
@@ -1094,27 +1114,47 @@ function useOutlit() {
|
|
|
1094
1114
|
console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
|
|
1095
1115
|
return;
|
|
1096
1116
|
}
|
|
1097
|
-
outlit.engaged(properties);
|
|
1117
|
+
outlit.user.engaged(properties);
|
|
1098
1118
|
},
|
|
1099
1119
|
[outlit]
|
|
1100
1120
|
);
|
|
1101
|
-
const
|
|
1121
|
+
const inactive = useCallback2(
|
|
1102
1122
|
(properties) => {
|
|
1103
1123
|
if (!outlit) {
|
|
1104
1124
|
console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
|
|
1105
1125
|
return;
|
|
1106
1126
|
}
|
|
1107
|
-
outlit.
|
|
1127
|
+
outlit.user.inactive(properties);
|
|
1128
|
+
},
|
|
1129
|
+
[outlit]
|
|
1130
|
+
);
|
|
1131
|
+
const trialing = useCallback2(
|
|
1132
|
+
(options) => {
|
|
1133
|
+
if (!outlit) {
|
|
1134
|
+
console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
outlit.customer.trialing(options);
|
|
1138
|
+
},
|
|
1139
|
+
[outlit]
|
|
1140
|
+
);
|
|
1141
|
+
const paid = useCallback2(
|
|
1142
|
+
(options) => {
|
|
1143
|
+
if (!outlit) {
|
|
1144
|
+
console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
outlit.customer.paid(options);
|
|
1108
1148
|
},
|
|
1109
1149
|
[outlit]
|
|
1110
1150
|
);
|
|
1111
1151
|
const churned = useCallback2(
|
|
1112
|
-
(
|
|
1152
|
+
(options) => {
|
|
1113
1153
|
if (!outlit) {
|
|
1114
1154
|
console.warn("[Outlit] Not initialized. Make sure OutlitProvider is mounted.");
|
|
1115
1155
|
return;
|
|
1116
1156
|
}
|
|
1117
|
-
outlit.churned(
|
|
1157
|
+
outlit.customer.churned(options);
|
|
1118
1158
|
},
|
|
1119
1159
|
[outlit]
|
|
1120
1160
|
);
|
|
@@ -1124,10 +1164,17 @@ function useOutlit() {
|
|
|
1124
1164
|
getVisitorId,
|
|
1125
1165
|
setUser,
|
|
1126
1166
|
clearUser,
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1167
|
+
user: {
|
|
1168
|
+
identify: userIdentify,
|
|
1169
|
+
activate,
|
|
1170
|
+
engaged,
|
|
1171
|
+
inactive
|
|
1172
|
+
},
|
|
1173
|
+
customer: {
|
|
1174
|
+
trialing,
|
|
1175
|
+
paid,
|
|
1176
|
+
churned
|
|
1177
|
+
},
|
|
1131
1178
|
isInitialized,
|
|
1132
1179
|
isTrackingEnabled,
|
|
1133
1180
|
enableTracking
|