@shware/analytics 7.4.0 → 7.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.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ALL_ENVIRONMENTS, ALL_PLATFORMS, CreateFeedbackDTO, CreateLinkDTO, createFeedbackSchema, createLinkSchema, createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from "./schema/index.cjs";
2
2
  import { sendFeedback } from "./feedback/index.cjs";
3
- import { AllowedPropertyValues, Environment, Platform, TrackProperties, TrackTags, UTMParams, UserProvidedData } from "./track/types.cjs";
3
+ import { AllowedPropertyValues, CustomEventProperties, Environment, Platform, TrackProperties, TrackTags, UTMParams, UserProvidedData } from "./track/types.cjs";
4
4
  import { useTrackImpression } from "./hooks/use-track-impression.cjs";
5
5
  import { VisitorProperties } from "./visitor/types.cjs";
6
6
  import { setupAnalytics } from "./setup/index.cjs";
@@ -8,4 +8,4 @@ import { sendBeacon, track, trackAsync } from "./track/index.cjs";
8
8
  import { getVisitor, setVisitor } from "./visitor/index.cjs";
9
9
  import { Link, createLink, getLink } from "./link/index.cjs";
10
10
  import { stripeMinorUnits } from "./utils/stripe.cjs";
11
- export { ALL_ENVIRONMENTS, ALL_PLATFORMS, type AllowedPropertyValues, type CreateFeedbackDTO, type CreateLinkDTO, type Environment, type Link, type Platform, type TrackProperties, type TrackTags, type UTMParams, type UserProvidedData, type VisitorProperties, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, getVisitor, sendBeacon, sendFeedback, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, updateVisitorSchema, useTrackImpression };
11
+ export { ALL_ENVIRONMENTS, ALL_PLATFORMS, type AllowedPropertyValues, type CreateFeedbackDTO, type CreateLinkDTO, type CustomEventProperties, type Environment, type Link, type Platform, type TrackProperties, type TrackTags, type UTMParams, type UserProvidedData, type VisitorProperties, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, getVisitor, sendBeacon, sendFeedback, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, updateVisitorSchema, useTrackImpression };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ALL_ENVIRONMENTS, ALL_PLATFORMS, CreateFeedbackDTO, CreateLinkDTO, createFeedbackSchema, createLinkSchema, createTrackEventSchema, createVisitorSchema, updateVisitorSchema } from "./schema/index.mjs";
2
2
  import { sendFeedback } from "./feedback/index.mjs";
3
- import { AllowedPropertyValues, Environment, Platform, TrackProperties, TrackTags, UTMParams, UserProvidedData } from "./track/types.mjs";
3
+ import { AllowedPropertyValues, CustomEventProperties, Environment, Platform, TrackProperties, TrackTags, UTMParams, UserProvidedData } from "./track/types.mjs";
4
4
  import { useTrackImpression } from "./hooks/use-track-impression.mjs";
5
5
  import { VisitorProperties } from "./visitor/types.mjs";
6
6
  import { setupAnalytics } from "./setup/index.mjs";
@@ -8,4 +8,4 @@ import { sendBeacon, track, trackAsync } from "./track/index.mjs";
8
8
  import { getVisitor, setVisitor } from "./visitor/index.mjs";
9
9
  import { Link, createLink, getLink } from "./link/index.mjs";
10
10
  import { stripeMinorUnits } from "./utils/stripe.mjs";
11
- export { ALL_ENVIRONMENTS, ALL_PLATFORMS, type AllowedPropertyValues, type CreateFeedbackDTO, type CreateLinkDTO, type Environment, type Link, type Platform, type TrackProperties, type TrackTags, type UTMParams, type UserProvidedData, type VisitorProperties, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, getVisitor, sendBeacon, sendFeedback, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, updateVisitorSchema, useTrackImpression };
11
+ export { ALL_ENVIRONMENTS, ALL_PLATFORMS, type AllowedPropertyValues, type CreateFeedbackDTO, type CreateLinkDTO, type CustomEventProperties, type Environment, type Link, type Platform, type TrackProperties, type TrackTags, type UTMParams, type UserProvidedData, type VisitorProperties, createFeedbackSchema, createLink, createLinkSchema, createTrackEventSchema, createVisitorSchema, getLink, getVisitor, sendBeacon, sendFeedback, setVisitor, setupAnalytics, stripeMinorUnits, track, trackAsync, updateVisitorSchema, useTrackImpression };
@@ -3,7 +3,41 @@ import { StandardEvents, UserProvidedData as UserProvidedData$1 } from "./gtag.c
3
3
  type AllowedPropertyValues = string | number | boolean | null;
4
4
  type EventName = Lowercase<string> | 'CLS' | 'FCP' | 'INP' | 'LCP' | 'TTFB';
5
5
  type TrackName<T extends EventName = EventName> = T extends keyof StandardEvents ? T : EventName;
6
- type TrackProperties<T extends EventName = EventName> = T extends keyof StandardEvents ? StandardEvents[T] : Record<Lowercase<string>, AllowedPropertyValues>;
6
+ /**
7
+ * Properties an application defines for its own events, keyed by event name.
8
+ *
9
+ * Empty here on purpose. Applications fill it by declaration merging, and it does two jobs:
10
+ * it adds custom properties to GA4's standard events, which are otherwise closed shapes and
11
+ * would need a cast; and it gives an application's own events a real type instead of the
12
+ * open record they fall back to.
13
+ *
14
+ * ```ts
15
+ * declare module '@shware/analytics' {
16
+ * interface CustomEventProperties {
17
+ * // Extra properties on a standard event.
18
+ * begin_checkout: { type?: 'new_purchase' | 'upgrade' };
19
+ * // The whole shape of an event this app defines itself.
20
+ * schedule_plan_change: { direction: 'upgrade' | 'downgrade'; effective_at: string };
21
+ * }
22
+ * }
23
+ * ```
24
+ *
25
+ * Keyed by event rather than a single flat set of properties, so a dimension cannot leak
26
+ * onto events it means nothing on. An event nobody declares keeps its previous type exactly,
27
+ * which is what makes adopting this optional and incremental.
28
+ *
29
+ * Note what "custom" attaches to: the *properties*, not the event. `begin_checkout` is one
30
+ * of GA4's recommended events and stays one — only the properties added here are custom.
31
+ */
32
+ interface CustomEventProperties {}
33
+ /**
34
+ * An application's declared properties for one event, or nothing if it declared none.
35
+ *
36
+ * `unknown` rather than `{}` for the empty case: it is the identity of `&`, so an event with
37
+ * no declaration intersects to exactly the type it had before.
38
+ */
39
+ type CustomPropertiesFor<T> = T extends keyof CustomEventProperties ? CustomEventProperties[T] : unknown;
40
+ type TrackProperties<T extends EventName = EventName> = T extends keyof StandardEvents ? StandardEvents[T] & CustomPropertiesFor<T> : T extends keyof CustomEventProperties ? CustomEventProperties[T] : Record<Lowercase<string>, AllowedPropertyValues>;
7
41
  type Platform = 'ios' | 'android' | 'web' | 'macos' | 'windows' | 'linux' | 'unknown';
8
42
  type Environment = 'development' | 'production';
9
43
  interface UserData {
@@ -172,5 +206,5 @@ type TrackEventResponse = {
172
206
  id: string;
173
207
  }[];
174
208
  //#endregion
175
- export { AdvertisingInfo, AllowedPropertyValues, AppInfo, DeviceInfo, Environment, EnvironmentInfo, EventName, PageInfo, Platform, PlatformInfo, ThirdPartyTracker, TrackEvent, TrackEventResponse, TrackName, TrackProperties, TrackTags, UTMParams, UserData, UserProvidedData };
209
+ export { AdvertisingInfo, AllowedPropertyValues, AppInfo, CustomEventProperties, DeviceInfo, Environment, EnvironmentInfo, EventName, PageInfo, Platform, PlatformInfo, ThirdPartyTracker, TrackEvent, TrackEventResponse, TrackName, TrackProperties, TrackTags, UTMParams, UserData, UserProvidedData };
176
210
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/track/types.ts"],"mappings":";;KAEY;KACA,YAAY;KAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;KACQ,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KACf,OAAO,mBAAmB;KAElB;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe,yBAAyB;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;KAGU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;;EAEf;EACA;;UAGe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;UAGe;;;;;;;EAOf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;EAEA;EACA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;UAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;UAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;KAGU;;EAEV"}
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/track/types.ts"],"mappings":";;KAEY;KACA,YAAY;KAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;KAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;KAEpB;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe,yBAAyB;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;KAGU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;;EAEf;EACA;;UAGe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;UAGe;;;;;;;EAOf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;EAEA;EACA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;UAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;UAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;KAGU;;EAEV"}
@@ -3,7 +3,41 @@ import { StandardEvents, UserProvidedData as UserProvidedData$1 } from "./gtag.m
3
3
  type AllowedPropertyValues = string | number | boolean | null;
4
4
  type EventName = Lowercase<string> | 'CLS' | 'FCP' | 'INP' | 'LCP' | 'TTFB';
5
5
  type TrackName<T extends EventName = EventName> = T extends keyof StandardEvents ? T : EventName;
6
- type TrackProperties<T extends EventName = EventName> = T extends keyof StandardEvents ? StandardEvents[T] : Record<Lowercase<string>, AllowedPropertyValues>;
6
+ /**
7
+ * Properties an application defines for its own events, keyed by event name.
8
+ *
9
+ * Empty here on purpose. Applications fill it by declaration merging, and it does two jobs:
10
+ * it adds custom properties to GA4's standard events, which are otherwise closed shapes and
11
+ * would need a cast; and it gives an application's own events a real type instead of the
12
+ * open record they fall back to.
13
+ *
14
+ * ```ts
15
+ * declare module '@shware/analytics' {
16
+ * interface CustomEventProperties {
17
+ * // Extra properties on a standard event.
18
+ * begin_checkout: { type?: 'new_purchase' | 'upgrade' };
19
+ * // The whole shape of an event this app defines itself.
20
+ * schedule_plan_change: { direction: 'upgrade' | 'downgrade'; effective_at: string };
21
+ * }
22
+ * }
23
+ * ```
24
+ *
25
+ * Keyed by event rather than a single flat set of properties, so a dimension cannot leak
26
+ * onto events it means nothing on. An event nobody declares keeps its previous type exactly,
27
+ * which is what makes adopting this optional and incremental.
28
+ *
29
+ * Note what "custom" attaches to: the *properties*, not the event. `begin_checkout` is one
30
+ * of GA4's recommended events and stays one — only the properties added here are custom.
31
+ */
32
+ interface CustomEventProperties {}
33
+ /**
34
+ * An application's declared properties for one event, or nothing if it declared none.
35
+ *
36
+ * `unknown` rather than `{}` for the empty case: it is the identity of `&`, so an event with
37
+ * no declaration intersects to exactly the type it had before.
38
+ */
39
+ type CustomPropertiesFor<T> = T extends keyof CustomEventProperties ? CustomEventProperties[T] : unknown;
40
+ type TrackProperties<T extends EventName = EventName> = T extends keyof StandardEvents ? StandardEvents[T] & CustomPropertiesFor<T> : T extends keyof CustomEventProperties ? CustomEventProperties[T] : Record<Lowercase<string>, AllowedPropertyValues>;
7
41
  type Platform = 'ios' | 'android' | 'web' | 'macos' | 'windows' | 'linux' | 'unknown';
8
42
  type Environment = 'development' | 'production';
9
43
  interface UserData {
@@ -172,5 +206,5 @@ type TrackEventResponse = {
172
206
  id: string;
173
207
  }[];
174
208
  //#endregion
175
- export { AdvertisingInfo, AllowedPropertyValues, AppInfo, DeviceInfo, Environment, EnvironmentInfo, EventName, PageInfo, Platform, PlatformInfo, ThirdPartyTracker, TrackEvent, TrackEventResponse, TrackName, TrackProperties, TrackTags, UTMParams, UserData, UserProvidedData };
209
+ export { AdvertisingInfo, AllowedPropertyValues, AppInfo, CustomEventProperties, DeviceInfo, Environment, EnvironmentInfo, EventName, PageInfo, Platform, PlatformInfo, ThirdPartyTracker, TrackEvent, TrackEventResponse, TrackName, TrackProperties, TrackTags, UTMParams, UserData, UserProvidedData };
176
210
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/track/types.ts"],"mappings":";;KAEY;KACA,YAAY;KAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;KACQ,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KACf,OAAO,mBAAmB;KAElB;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe,yBAAyB;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;KAGU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;;EAEf;EACA;;UAGe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;UAGe;;;;;;;EAOf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;EAEA;EACA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;UAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;UAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;KAGU;;EAEV"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/track/types.ts"],"mappings":";;KAEY;KACA,YAAY;KAEZ,UAAU,UAAU,YAAY,aAAa,gBAAgB,iBACrE,IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+Ba;;;;;;;KAQZ,oBAAoB,KAAK,gBAAgB,wBAC1C,sBAAsB;KAGd,gBAAgB,UAAU,YAAY,aAAa,gBAAgB,iBAC3E,eAAe,KAAK,oBAAoB,KACxC,gBAAgB,wBACd,sBAAsB,KACtB,OAAO,mBAAmB;KAEpB;KACA;UAEK;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe,yBAAyB;EACxC;EACA;EACA;EACA;EACA;IAAa;IAAc;IAAe;;EAE1C;EACA;;KAGU,qBAAqB,UAAU,WACzC,MAAM,UAAU,IAChB,aAAa,gBAAgB,IAC7B;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;UAGe;;EAEf;EACA;;UAGe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;UAGe;;;;;;;EAOf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;;EAEA;EACA;;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;;UAQe;;EAEf;;;;;;;;;;;;EAqCA;;;;;;EAuDA;;EAMA;;EAEA;;EAEA;;EAEA;;EAUA;;EAEA;;UAGe,kBACP,cAAc,YAAY,SAAS,iBAAiB,UAAU,iBAAiB;EACvF;GACC;;UAGc,WAAW,UAAU,YAAY;EAChD;EACA,MAAM,UAAU;EAChB,MAAM;EACN;EACA;EACA,UAAU;EACV,aAAa;EACb,aAAa,gBAAgB;EAC7B;;KAGU;;EAEV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/analytics",
3
- "version": "7.4.0",
3
+ "version": "7.5.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",