@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,9 +1,11 @@
1
+ // src/vue/composables.ts
2
+ import { inject, watch as watch2 } from "vue";
3
+
1
4
  // src/vue/plugin.ts
2
5
  import { readonly, ref, shallowRef, watch } from "vue";
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,18 @@ 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
+ customerTraits: options.customerTraits,
814
+ traits: options.traits
804
815
  };
805
816
  if (hadNoUser) {
806
817
  this.flushPendingStageEvents();
@@ -811,6 +822,8 @@ var Outlit = class {
811
822
  referrer: document.referrer,
812
823
  email: options.email,
813
824
  userId: options.userId,
825
+ customerId: options.customerId,
826
+ customerTraits: options.customerTraits,
814
827
  traits: options.traits
815
828
  });
816
829
  this.enqueue(event);
@@ -852,7 +865,13 @@ var Outlit = class {
852
865
  */
853
866
  applyUser(identity) {
854
867
  this.currentUser = identity;
855
- this.identify({ email: identity.email, userId: identity.userId, traits: identity.traits });
868
+ this.identify({
869
+ email: identity.email,
870
+ userId: identity.userId,
871
+ traits: identity.traits,
872
+ customerId: identity.customerId,
873
+ customerTraits: identity.customerTraits
874
+ });
856
875
  this.flushPendingStageEvents();
857
876
  }
858
877
  /**
@@ -920,13 +939,18 @@ var Outlit = class {
920
939
  console.warn("[Outlit] Tracking not enabled. Call enableTracking() first.");
921
940
  return;
922
941
  }
942
+ try {
943
+ validateCustomerIdentity(options.customerId, options.stripeCustomerId);
944
+ } catch (error) {
945
+ console.warn("[Outlit]", error instanceof Error ? error.message : error);
946
+ return;
947
+ }
923
948
  const event = buildBillingEvent({
924
949
  url: window.location.href,
925
950
  referrer: document.referrer,
926
951
  status,
927
952
  customerId: options.customerId,
928
953
  stripeCustomerId: options.stripeCustomerId,
929
- domain: options.domain,
930
954
  properties: options.properties
931
955
  });
932
956
  this.enqueue(event);
@@ -1042,12 +1066,46 @@ var Outlit = class {
1042
1066
  this.flush();
1043
1067
  }, this.flushInterval);
1044
1068
  }
1069
+ getPayloadUserIdentity() {
1070
+ if (!this.currentUser) {
1071
+ return void 0;
1072
+ }
1073
+ const { email, userId } = this.currentUser;
1074
+ if (!email && !userId) {
1075
+ return void 0;
1076
+ }
1077
+ return {
1078
+ ...email && { email },
1079
+ ...userId && { userId }
1080
+ };
1081
+ }
1082
+ getPayloadCustomerIdentity() {
1083
+ if (!this.currentUser) {
1084
+ return void 0;
1085
+ }
1086
+ const { customerId } = this.currentUser;
1087
+ if (!customerId) {
1088
+ return void 0;
1089
+ }
1090
+ return {
1091
+ ...customerId && { customerId }
1092
+ };
1093
+ }
1045
1094
  async sendEvents(events) {
1046
1095
  if (events.length === 0) return;
1047
1096
  if (!this.visitorId) return;
1048
- const userIdentity = this.currentUser ?? void 0;
1097
+ const userIdentity = this.getPayloadUserIdentity();
1098
+ const customerIdentity = this.getPayloadCustomerIdentity();
1049
1099
  const sessionId = this.sessionTracker?.getSessionId();
1050
- const payload = buildIngestPayload(this.visitorId, "client", events, userIdentity, sessionId);
1100
+ const payload = buildIngestPayload(
1101
+ this.visitorId,
1102
+ "client",
1103
+ events,
1104
+ userIdentity,
1105
+ sessionId,
1106
+ void 0,
1107
+ customerIdentity
1108
+ );
1051
1109
  const url = `${this.apiHost}/api/i/v1/${this.publicKey}/events`;
1052
1110
  try {
1053
1111
  if (typeof navigator !== "undefined" && navigator.sendBeacon) {
@@ -1141,7 +1199,6 @@ var OutlitPlugin = {
1141
1199
  };
1142
1200
 
1143
1201
  // src/vue/composables.ts
1144
- import { inject, watch as watch2 } from "vue";
1145
1202
  function useOutlit() {
1146
1203
  const instance = inject(OutlitKey);
1147
1204
  if (!instance) {