@outlit/browser 1.4.3 → 1.5.0

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.
@@ -1,50 +1,6 @@
1
- import { ShallowRef, Ref, InjectionKey, App } from 'vue';
2
- import { O as Outlit, U as UserIdentity, h as OutlitOptions, B as BillingOptions } from '../tracker-CzhtZoOC.mjs';
3
1
  import { BrowserIdentifyOptions, BrowserTrackOptions } from '@outlit/core';
4
-
5
- interface OutlitPluginOptions extends Omit<OutlitOptions, "trackPageviews"> {
6
- /**
7
- * Whether to automatically track pageviews.
8
- * @default true
9
- */
10
- trackPageviews?: boolean;
11
- /**
12
- * Whether to start tracking automatically.
13
- * Set to false if you need to wait for user consent.
14
- * @default true
15
- */
16
- autoTrack?: boolean;
17
- }
18
- interface OutlitInstance {
19
- outlit: ShallowRef<Outlit | null>;
20
- isInitialized: Readonly<Ref<boolean>>;
21
- isTrackingEnabled: Readonly<Ref<boolean>>;
22
- enableTracking: () => void;
23
- disableTracking: () => void;
24
- /**
25
- * Set the current user. Automatically calls identify when user changes.
26
- * Pass null to clear the user (logout).
27
- */
28
- setUser: (user: UserIdentity | null) => void;
29
- }
30
- declare const OutlitKey: InjectionKey<OutlitInstance>;
31
- /**
32
- * Vue plugin to install Outlit.
33
- *
34
- * @example
35
- * ```ts
36
- * // main.ts
37
- * import { createApp } from 'vue'
38
- * import { OutlitPlugin } from '@outlit/browser/vue'
39
- *
40
- * const app = createApp(App)
41
- * app.use(OutlitPlugin, { publicKey: 'pk_xxx' })
42
- * app.mount('#app')
43
- * ```
44
- */
45
- declare const OutlitPlugin: {
46
- install(app: App, options: OutlitPluginOptions): void;
47
- };
2
+ import { Ref, ShallowRef, InjectionKey, App } from 'vue';
3
+ import { U as UserIdentity, B as BillingOptions, O as Outlit, h as OutlitOptions } from '../tracker-DlHUyaah.mjs';
48
4
 
49
5
  interface UseOutlitReturn {
50
6
  /**
@@ -201,4 +157,48 @@ type UseTrackReturn = ReturnType<typeof useTrack>;
201
157
  */
202
158
  type UseIdentifyReturn = ReturnType<typeof useIdentify>;
203
159
 
160
+ interface OutlitPluginOptions extends Omit<OutlitOptions, "trackPageviews"> {
161
+ /**
162
+ * Whether to automatically track pageviews.
163
+ * @default true
164
+ */
165
+ trackPageviews?: boolean;
166
+ /**
167
+ * Whether to start tracking automatically.
168
+ * Set to false if you need to wait for user consent.
169
+ * @default true
170
+ */
171
+ autoTrack?: boolean;
172
+ }
173
+ interface OutlitInstance {
174
+ outlit: ShallowRef<Outlit | null>;
175
+ isInitialized: Readonly<Ref<boolean>>;
176
+ isTrackingEnabled: Readonly<Ref<boolean>>;
177
+ enableTracking: () => void;
178
+ disableTracking: () => void;
179
+ /**
180
+ * Set the current user. Automatically calls identify when user changes.
181
+ * Pass null to clear the user (logout).
182
+ */
183
+ setUser: (user: UserIdentity | null) => void;
184
+ }
185
+ declare const OutlitKey: InjectionKey<OutlitInstance>;
186
+ /**
187
+ * Vue plugin to install Outlit.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * // main.ts
192
+ * import { createApp } from 'vue'
193
+ * import { OutlitPlugin } from '@outlit/browser/vue'
194
+ *
195
+ * const app = createApp(App)
196
+ * app.use(OutlitPlugin, { publicKey: 'pk_xxx' })
197
+ * app.mount('#app')
198
+ * ```
199
+ */
200
+ declare const OutlitPlugin: {
201
+ install(app: App, options: OutlitPluginOptions): void;
202
+ };
203
+
204
204
  export { type OutlitInstance, OutlitKey, OutlitPlugin, type OutlitPluginOptions, type UseIdentifyReturn, type UseOutlitReturn, type UseTrackReturn, useIdentify, useOutlit, useOutlitUser, useTrack };
@@ -1,50 +1,6 @@
1
- import { ShallowRef, Ref, InjectionKey, App } from 'vue';
2
- import { O as Outlit, U as UserIdentity, h as OutlitOptions, B as BillingOptions } from '../tracker-CzhtZoOC.js';
3
1
  import { BrowserIdentifyOptions, BrowserTrackOptions } from '@outlit/core';
4
-
5
- interface OutlitPluginOptions extends Omit<OutlitOptions, "trackPageviews"> {
6
- /**
7
- * Whether to automatically track pageviews.
8
- * @default true
9
- */
10
- trackPageviews?: boolean;
11
- /**
12
- * Whether to start tracking automatically.
13
- * Set to false if you need to wait for user consent.
14
- * @default true
15
- */
16
- autoTrack?: boolean;
17
- }
18
- interface OutlitInstance {
19
- outlit: ShallowRef<Outlit | null>;
20
- isInitialized: Readonly<Ref<boolean>>;
21
- isTrackingEnabled: Readonly<Ref<boolean>>;
22
- enableTracking: () => void;
23
- disableTracking: () => void;
24
- /**
25
- * Set the current user. Automatically calls identify when user changes.
26
- * Pass null to clear the user (logout).
27
- */
28
- setUser: (user: UserIdentity | null) => void;
29
- }
30
- declare const OutlitKey: InjectionKey<OutlitInstance>;
31
- /**
32
- * Vue plugin to install Outlit.
33
- *
34
- * @example
35
- * ```ts
36
- * // main.ts
37
- * import { createApp } from 'vue'
38
- * import { OutlitPlugin } from '@outlit/browser/vue'
39
- *
40
- * const app = createApp(App)
41
- * app.use(OutlitPlugin, { publicKey: 'pk_xxx' })
42
- * app.mount('#app')
43
- * ```
44
- */
45
- declare const OutlitPlugin: {
46
- install(app: App, options: OutlitPluginOptions): void;
47
- };
2
+ import { Ref, ShallowRef, InjectionKey, App } from 'vue';
3
+ import { U as UserIdentity, B as BillingOptions, O as Outlit, h as OutlitOptions } from '../tracker-DlHUyaah.js';
48
4
 
49
5
  interface UseOutlitReturn {
50
6
  /**
@@ -201,4 +157,48 @@ type UseTrackReturn = ReturnType<typeof useTrack>;
201
157
  */
202
158
  type UseIdentifyReturn = ReturnType<typeof useIdentify>;
203
159
 
160
+ interface OutlitPluginOptions extends Omit<OutlitOptions, "trackPageviews"> {
161
+ /**
162
+ * Whether to automatically track pageviews.
163
+ * @default true
164
+ */
165
+ trackPageviews?: boolean;
166
+ /**
167
+ * Whether to start tracking automatically.
168
+ * Set to false if you need to wait for user consent.
169
+ * @default true
170
+ */
171
+ autoTrack?: boolean;
172
+ }
173
+ interface OutlitInstance {
174
+ outlit: ShallowRef<Outlit | null>;
175
+ isInitialized: Readonly<Ref<boolean>>;
176
+ isTrackingEnabled: Readonly<Ref<boolean>>;
177
+ enableTracking: () => void;
178
+ disableTracking: () => void;
179
+ /**
180
+ * Set the current user. Automatically calls identify when user changes.
181
+ * Pass null to clear the user (logout).
182
+ */
183
+ setUser: (user: UserIdentity | null) => void;
184
+ }
185
+ declare const OutlitKey: InjectionKey<OutlitInstance>;
186
+ /**
187
+ * Vue plugin to install Outlit.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * // main.ts
192
+ * import { createApp } from 'vue'
193
+ * import { OutlitPlugin } from '@outlit/browser/vue'
194
+ *
195
+ * const app = createApp(App)
196
+ * app.use(OutlitPlugin, { publicKey: 'pk_xxx' })
197
+ * app.mount('#app')
198
+ * ```
199
+ */
200
+ declare const OutlitPlugin: {
201
+ install(app: App, options: OutlitPluginOptions): void;
202
+ };
203
+
204
204
  export { type OutlitInstance, OutlitKey, OutlitPlugin, type OutlitPluginOptions, type UseIdentifyReturn, type UseOutlitReturn, type UseTrackReturn, useIdentify, useOutlit, useOutlitUser, useTrack };
package/dist/vue/index.js CHANGED
@@ -29,6 +29,9 @@ __export(vue_exports, {
29
29
  });
30
30
  module.exports = __toCommonJS(vue_exports);
31
31
 
32
+ // src/vue/composables.ts
33
+ var import_vue2 = require("vue");
34
+
32
35
  // src/vue/plugin.ts
33
36
  var import_vue = require("vue");
34
37
 
@@ -817,11 +820,18 @@ var Outlit = class {
817
820
  console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
818
821
  return;
819
822
  }
823
+ if (!options.email && !options.userId) {
824
+ console.warn("[Outlit] identify requires email or userId");
825
+ return;
826
+ }
820
827
  if (options.email || options.userId) {
821
828
  const hadNoUser = !this.currentUser;
822
829
  this.currentUser = {
823
830
  email: options.email,
824
- userId: options.userId
831
+ userId: options.userId,
832
+ customerId: options.customerId,
833
+ customerTraits: options.customerTraits,
834
+ traits: options.traits
825
835
  };
826
836
  if (hadNoUser) {
827
837
  this.flushPendingStageEvents();
@@ -832,6 +842,8 @@ var Outlit = class {
832
842
  referrer: document.referrer,
833
843
  email: options.email,
834
844
  userId: options.userId,
845
+ customerId: options.customerId,
846
+ customerTraits: options.customerTraits,
835
847
  traits: options.traits
836
848
  });
837
849
  this.enqueue(event);
@@ -873,7 +885,13 @@ var Outlit = class {
873
885
  */
874
886
  applyUser(identity) {
875
887
  this.currentUser = identity;
876
- this.identify({ email: identity.email, userId: identity.userId, traits: identity.traits });
888
+ this.identify({
889
+ email: identity.email,
890
+ userId: identity.userId,
891
+ traits: identity.traits,
892
+ customerId: identity.customerId,
893
+ customerTraits: identity.customerTraits
894
+ });
877
895
  this.flushPendingStageEvents();
878
896
  }
879
897
  /**
@@ -941,13 +959,18 @@ var Outlit = class {
941
959
  console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
942
960
  return;
943
961
  }
962
+ try {
963
+ (0, import_core3.validateCustomerIdentity)(options.customerId, options.stripeCustomerId);
964
+ } catch (error) {
965
+ console.warn("[Outlit]", error instanceof Error ? error.message : error);
966
+ return;
967
+ }
944
968
  const event = (0, import_core3.buildBillingEvent)({
945
969
  url: window.location.href,
946
970
  referrer: document.referrer,
947
971
  status,
948
972
  customerId: options.customerId,
949
973
  stripeCustomerId: options.stripeCustomerId,
950
- domain: options.domain,
951
974
  properties: options.properties
952
975
  });
953
976
  this.enqueue(event);
@@ -1063,12 +1086,46 @@ var Outlit = class {
1063
1086
  this.flush();
1064
1087
  }, this.flushInterval);
1065
1088
  }
1089
+ getPayloadUserIdentity() {
1090
+ if (!this.currentUser) {
1091
+ return void 0;
1092
+ }
1093
+ const { email, userId } = this.currentUser;
1094
+ if (!email && !userId) {
1095
+ return void 0;
1096
+ }
1097
+ return {
1098
+ ...email && { email },
1099
+ ...userId && { userId }
1100
+ };
1101
+ }
1102
+ getPayloadCustomerIdentity() {
1103
+ if (!this.currentUser) {
1104
+ return void 0;
1105
+ }
1106
+ const { customerId } = this.currentUser;
1107
+ if (!customerId) {
1108
+ return void 0;
1109
+ }
1110
+ return {
1111
+ ...customerId && { customerId }
1112
+ };
1113
+ }
1066
1114
  async sendEvents(events) {
1067
1115
  if (events.length === 0) return;
1068
1116
  if (!this.visitorId) return;
1069
- const userIdentity = this.currentUser ?? void 0;
1117
+ const userIdentity = this.getPayloadUserIdentity();
1118
+ const customerIdentity = this.getPayloadCustomerIdentity();
1070
1119
  const sessionId = this.sessionTracker?.getSessionId();
1071
- const payload = (0, import_core3.buildIngestPayload)(this.visitorId, "client", events, userIdentity, sessionId);
1120
+ const payload = (0, import_core3.buildIngestPayload)(
1121
+ this.visitorId,
1122
+ "client",
1123
+ events,
1124
+ userIdentity,
1125
+ sessionId,
1126
+ void 0,
1127
+ customerIdentity
1128
+ );
1072
1129
  const url = `${this.apiHost}/api/i/v1/${this.publicKey}/events`;
1073
1130
  try {
1074
1131
  if (typeof navigator !== "undefined" && navigator.sendBeacon) {
@@ -1162,7 +1219,6 @@ var OutlitPlugin = {
1162
1219
  };
1163
1220
 
1164
1221
  // src/vue/composables.ts
1165
- var import_vue2 = require("vue");
1166
1222
  function useOutlit() {
1167
1223
  const instance = (0, import_vue2.inject)(OutlitKey);
1168
1224
  if (!instance) {