@reservamos/browser-analytics 0.2.2 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reservamos/browser-analytics",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/reservamos/reservamos-browser-analytics.git"
@@ -1,19 +1,25 @@
1
+ import type { EventData, EventMetadata } from '@/types/eventData';
1
2
  import { trackEvent } from '@/track';
2
- import EventData from '@/types/eventData';
3
3
  import { eventNameSchema } from './customEventSchema';
4
4
 
5
5
  /**
6
6
  * Tracks a custom event with any event name, data, and metadata.
7
7
  * @param {string} eventName - The name of the custom event.
8
8
  * @param {EventData} eventData - Additional data to include in the event.
9
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
9
10
  */
10
- function trackCustomEvent(eventName: string, eventData: EventData = {}): void {
11
+ function trackCustomEvent(
12
+ eventName: string,
13
+ eventData: EventData = {},
14
+ meta: EventMetadata = {},
15
+ ): void {
11
16
  try {
12
17
  eventNameSchema.parse(eventName);
13
- trackEvent(eventName, eventData);
18
+ trackEvent(eventName, eventData, meta);
14
19
  } catch (error) {
15
20
  console.error('Error trackCustomEvent:', error);
16
21
  return;
17
22
  }
18
23
  }
24
+
19
25
  export default trackCustomEvent;
@@ -1,17 +1,17 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { InterestInHomeProps } from './interestInHomeSchema';
2
3
  import { trackEvent } from '@/track';
3
- import EventData from '@/types/eventData';
4
4
 
5
5
  const EVENT_NAME = 'Interest In Home';
6
6
 
7
7
  /**
8
8
  * Tracks a Interest In Home event.
9
9
  * @param {InterestInHomeProps} eventData - The data associated with the Interest In Home event.
10
- * @param {EventData} meta - Additional metadata to include in the event.
10
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
11
11
  */
12
12
  function trackInterestInHome(
13
13
  eventData: InterestInHomeProps,
14
- meta: EventData = {},
14
+ meta: EventMetadata = {},
15
15
  ): void {
16
16
  trackEvent(EVENT_NAME, eventData, meta);
17
17
  }
@@ -1,17 +1,17 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { InterestInSearchProps } from './interestInSearchSchema';
2
3
  import { trackEvent } from '@/track';
3
- import EventData from '@/types/eventData';
4
4
 
5
5
  const EVENT_NAME = 'Interest In Search';
6
6
 
7
7
  /**
8
8
  * Tracks a Interest In Search event.
9
9
  * @param {InterestInSearchProps} eventData - The data associated with the Interest In Search event.
10
- * @param {EventData} meta - Additional metadata to include in the event.
10
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
11
11
  */
12
12
  function trackInterestInSearch(
13
13
  eventData: InterestInSearchProps,
14
- meta: EventData = {},
14
+ meta: EventMetadata = {},
15
15
  ): void {
16
16
  trackEvent(EVENT_NAME, eventData, meta);
17
17
  }
@@ -1,17 +1,17 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { PassengersCreatedProps } from './passengersCreatedSchema';
2
3
  import { trackEvent } from '@/track';
3
- import EventData from '@/types/eventData';
4
4
 
5
5
  const EVENT_NAME = 'Passengers Created';
6
6
 
7
7
  /**
8
8
  * Tracks a Passengers Created event.
9
9
  * @param {PassengersCreatedProps} eventProps - The data associated with the Passengers Created event.
10
- * @param {EventData} meta - Additional metadata to include in the event.
10
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
11
11
  */
12
12
  function trackPassengersCreated(
13
13
  eventProps: PassengersCreatedProps,
14
- meta: EventData = {},
14
+ meta: EventMetadata = {},
15
15
  ): void {
16
16
  trackEvent(EVENT_NAME, eventProps, meta);
17
17
  }
@@ -1,10 +1,14 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { PaymentAttemptProps } from './paymentAttemptSchema';
2
3
  import { trackEvent } from '@/track';
3
4
 
4
5
  const EVENT_NAME = 'Payment Attempt';
5
6
 
6
- const trackPaymentAttempt = async (eventProps: PaymentAttemptProps) => {
7
- trackEvent(EVENT_NAME, eventProps);
7
+ const trackPaymentAttempt = async (
8
+ eventProps: PaymentAttemptProps,
9
+ meta: EventMetadata = {},
10
+ ) => {
11
+ trackEvent(EVENT_NAME, eventProps, meta);
8
12
  };
9
13
 
10
14
  export default trackPaymentAttempt;
@@ -1,17 +1,17 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { PickedDepartureProps } from './pickedDepartureSchema';
2
3
  import { trackEvent } from '@/track';
3
- import EventData from '@/types/eventData';
4
4
 
5
5
  const EVENT_NAME = 'Picked Departure';
6
6
 
7
7
  /**
8
8
  * Tracks a Picked Departure event.
9
9
  * @param {PickedDepartureProps} eventData - The data associated with the Picked Departure event.
10
- * @param {EventData} meta - Additional metadata to include in the event.
10
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
11
11
  */
12
12
  function trackSearch(
13
13
  eventData: PickedDepartureProps,
14
- meta: EventData = {},
14
+ meta: EventMetadata = {},
15
15
  ): void {
16
16
  trackEvent(EVENT_NAME, eventData, meta);
17
17
  }
@@ -1,17 +1,17 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { PurchaseAttemptProps } from './purchaseAttemptSchema';
2
3
  import { trackEvent } from '@/track';
3
- import EventData from '@/types/eventData';
4
4
 
5
5
  const EVENT_NAME = 'Purchase Attempt';
6
6
 
7
7
  /**
8
8
  * Tracks a Purchase Attempt event.
9
9
  * @param {PurchaseAttemptProps} eventData - The data associated with the Purchase Attempt event.
10
- * @param {EventData} meta - Additional metadata to include in the event.
10
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
11
11
  */
12
12
  function trackPurchaseAttempt(
13
13
  eventData: PurchaseAttemptProps,
14
- meta: EventData = {},
14
+ meta: EventMetadata = {},
15
15
  ): void {
16
16
  trackEvent(EVENT_NAME, eventData, meta);
17
17
  }
@@ -1,15 +1,15 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { SearchProps } from './searchSchema';
2
3
  import { trackEvent } from '@/track';
3
- import EventData from '@/types/eventData';
4
4
 
5
5
  const EVENT_NAME = 'Search';
6
6
 
7
7
  /**
8
8
  * Tracks a search event.
9
9
  * @param {SearchProps} eventData - The data associated with the search event.
10
- * @param {EventData} meta - Additional metadata to include in the event.
10
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
11
11
  */
12
- function trackSearch(eventData: SearchProps, meta: EventData = {}): void {
12
+ function trackSearch(eventData: SearchProps, meta: EventMetadata = {}): void {
13
13
  trackEvent(EVENT_NAME, eventData, meta);
14
14
  }
15
15
 
@@ -1,17 +1,17 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { SeatChangeProps } from './seatChangeSchema';
2
3
  import { trackEvent } from '@/track';
3
- import EventData from '@/types/eventData';
4
4
 
5
5
  const EVENT_NAME = 'Seat Change';
6
6
 
7
7
  /**
8
8
  * Tracks a Seat Change event.
9
9
  * @param {SeatChangeProps} eventProps - The data associated with the Seat Change event.
10
- * @param {EventData} meta - Additional metadata to include in the event.
10
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
11
11
  */
12
12
  function trackSeatChange(
13
13
  eventProps: SeatChangeProps,
14
- meta: EventData = {},
14
+ meta: EventMetadata = {},
15
15
  ): void {
16
16
  trackEvent(EVENT_NAME, eventProps, meta);
17
17
  }
@@ -1,17 +1,17 @@
1
+ import type { EventMetadata } from '@/types/eventData';
1
2
  import type { ViewResultsProps } from './viewResultsSchema';
2
3
  import { trackEvent } from '@/track';
3
- import EventData from '@/types/eventData';
4
4
 
5
5
  const EVENT_NAME = 'View Results';
6
6
 
7
7
  /**
8
8
  * Tracks a View Results event.
9
9
  * @param {ViewResultsProps} eventData - The data associated with the View Results event.
10
- * @param {EventData} meta - Additional metadata to include in the event.
10
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
11
11
  */
12
12
  function trackViewResults(
13
13
  eventData: ViewResultsProps,
14
- meta: EventData = {},
14
+ meta: EventMetadata = {},
15
15
  ): void {
16
16
  trackEvent(EVENT_NAME, eventData, meta);
17
17
  }
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ import type { SearchProps } from '@/events/search';
9
9
  import type { SeatChangeProps } from '@/events/seatChange';
10
10
  import type { ViewResultsProps } from '@/events/viewResults';
11
11
  import type { CreateAnonymousProfileProps } from '@/profiles/createAnonymousProfile';
12
+ import type { EventData, EventMetadata } from '@/types/eventData';
12
13
  import trackCustomEvent from '@/events/customEvent';
13
14
  import identify from '@/events/identify';
14
15
  import trackInterestInHome from '@/events/interestInHome';
@@ -19,9 +20,8 @@ import trackPickedDeparture from '@/events/pickedDeparture';
19
20
  import trackPurchaseAttempt from '@/events/purchaseAttempt';
20
21
  import trackSearch from '@/events/search';
21
22
  import trackSeatChange from '@/events/seatChange';
22
- import trackTest from '@/events/test';
23
23
  import trackViewResults from '@/events/viewResults';
24
- import { init } from '@/init';
24
+ import init, { isTrackerReady } from '@/init';
25
25
  import createAnonymousProfile from '@/profiles/createAnonymousProfile';
26
26
  import fingerprintService from '@/services/fingerprint';
27
27
  import mixpanelService from '@/services/mixpanel';
@@ -29,6 +29,7 @@ import './js-api-client.d.ts';
29
29
 
30
30
  const analytics = {
31
31
  init,
32
+ isReady: isTrackerReady,
32
33
  identify,
33
34
  identifiers: {
34
35
  getFingerprintId: fingerprintService.getCachedFingerprint,
@@ -38,7 +39,6 @@ const analytics = {
38
39
  createAnonymousProfile,
39
40
  },
40
41
  track: {
41
- test: trackTest,
42
42
  search: trackSearch,
43
43
  seatChange: trackSeatChange,
44
44
  interestInHome: trackInterestInHome,
@@ -64,5 +64,8 @@ export type {
64
64
  PickedDepartureProps,
65
65
  CustomEventProps,
66
66
  CreateAnonymousProfileProps,
67
+ EventMetadata,
68
+ EventData,
67
69
  };
70
+
68
71
  export default analytics;
package/src/init.ts CHANGED
@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
  import configService from '@/services/config';
4
4
  import fingerprintService from '@/services/fingerprint';
5
5
  import mixpanelService from '@/services/mixpanel';
6
- import validator, { InitConfigSchema } from './services/validator';
6
+ import validator, { InitConfigSchema } from '@/services/validator';
7
7
 
8
8
  /**
9
9
  * Configuration object for initializing the tracking library.
@@ -25,7 +25,7 @@ function onLoaded() {
25
25
  * @param {InitConfig} config - The configuration object for initialization.
26
26
  * @throws {Error} Throws an error if the configuration is invalid.
27
27
  */
28
- export async function init(config: InitConfig) {
28
+ async function init(config: InitConfig) {
29
29
  validator.parseInitProps(config);
30
30
 
31
31
  const {
@@ -64,6 +64,9 @@ export async function init(config: InitConfig) {
64
64
  * This function verifies whether the Mixpanel tracker has been initialized and is ready to use.
65
65
  * @returns {boolean} Returns true if the Mixpanel tracker is ready, otherwise false.
66
66
  */
67
- export function isTrackerReady(): boolean {
67
+ function isTrackerReady(): boolean {
68
68
  return mixpanelService.isReady();
69
69
  }
70
+
71
+ export { isTrackerReady };
72
+ export default init;
@@ -30,7 +30,7 @@ export const InitConfigSchema = z.object({
30
30
  * Optional flag to determine if the sandbox environment should be used.
31
31
  * When set to true, the sandbox environment will be used; otherwise, the production environment will be used.
32
32
  */
33
- isSandbox: z.boolean().optional().default(false),
33
+ isSandbox: z.boolean().optional(),
34
34
  /**
35
35
  * Optional proxy URL for Mixpanel requests.
36
36
  */
package/src/track.ts CHANGED
@@ -1,7 +1,11 @@
1
+ import type {
2
+ AllowedPrimitive,
3
+ EventData,
4
+ EventMetadata,
5
+ } from './types/eventData';
1
6
  import fingerprintService from '@/services/fingerprint';
2
7
  import mixpanelService from '@/services/mixpanel';
3
8
  import validator from '@/services/validator';
4
- import EventData, { AllowedPrimitive } from './types/eventData';
5
9
 
6
10
  /**
7
11
  * List of events that trigger the fingerprint to be sent with the event. other events will only fetch the cached fingerprint.
@@ -43,13 +47,13 @@ function flattenEventData(data: object): EventData {
43
47
  * This function adds default properties like User Fingerprint.
44
48
  * @param {string} eventName - The name of the event to track.
45
49
  * @param {object} eventProperties - The properties of the event to track.
46
- * @param {EventData} meta - Additional metadata to include in the event.
50
+ * @param {EventMetadata} meta - Additional metadata to include in the event.
47
51
  * @throws {Error} Throws an error if Mixpanel or Fingerprint is not ready.
48
52
  */
49
53
  export async function trackEvent(
50
54
  eventName: string,
51
55
  eventProperties: object,
52
- meta: EventData = {},
56
+ meta: EventMetadata = {},
53
57
  ): Promise<void> {
54
58
  if (!mixpanelService.isReady()) {
55
59
  throw new Error('Mixpanel is not initialized.');
@@ -1,5 +1,7 @@
1
- export type AllowedPrimitive = string | boolean | number | undefined;
1
+ type AllowedPrimitive = string | boolean | number | undefined;
2
2
 
3
3
  type EventData = Record<string, AllowedPrimitive | AllowedPrimitive[]>;
4
4
 
5
- export default EventData;
5
+ type EventMetadata = EventData;
6
+
7
+ export type { EventData, AllowedPrimitive, EventMetadata };
@@ -1,3 +0,0 @@
1
- import trackTest from './trackTest';
2
-
3
- export default trackTest;
@@ -1,12 +0,0 @@
1
- import { trackEvent } from '@/track';
2
-
3
- const EVENT_NAME = 'Track Test';
4
-
5
- /**
6
- First test event to track, it purpose is to test the tracking library and the identification service.ws
7
- */
8
- function trackTest() {
9
- trackEvent(EVENT_NAME, {});
10
- }
11
-
12
- export default trackTest;