fleek-track-analytics 0.0.93 → 0.0.94

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/README.md ADDED
@@ -0,0 +1,193 @@
1
+ # fleek-track-analytics
2
+
3
+ fleek-track-analytics provides multiplatform support for integrating a type safe event tracking mechanism. The library provides web, node and react-native utils to initialise and track events
4
+ with trace(session) management.
5
+
6
+ ### Table of Contents
7
+
8
+ - [How to integrate](#how-to-integrate)
9
+ - [How to setup for development](#how-to-setup-for-development)
10
+ - [How to change event map](#how-to-change-event-map)
11
+ - [How to publish changes to npm](#how-to-publish-changes-to-npm)
12
+
13
+ ---
14
+
15
+ # How to Integrate
16
+
17
+ 1. Install the package
18
+ ```sh
19
+ # npm
20
+ npm install fleek-track-analytics
21
+
22
+ # yarn
23
+ yarn add fleek-track-analytics
24
+ ```
25
+
26
+ 2. Import based on platform
27
+ ```ts
28
+ # node
29
+ import { TrackAnalytics } from "fleek-track-analytics/lib/node";
30
+
31
+ #web
32
+ import { TrackAnalytics } from "fleek-track-analytics/lib/web";
33
+
34
+ #react-native
35
+ import { TrackAnalytics } from "fleek-track-analytics/lib/web";
36
+ ```
37
+
38
+ 3. Initialise TrackAnalytics.
39
+
40
+ ```ts
41
+ import { TrackAnalytics } from 'fleek-track-analytics/lib/__platform__';
42
+
43
+ const analyticsException = (e: unknown) => {
44
+ if (__DEV__) {
45
+ console.error(JSON.stringify(e));
46
+ } else {
47
+ // Note: you can log the errors to production error reporting
48
+ Sentry.captureException(e);
49
+ }
50
+ };
51
+
52
+ const analyticsWrapper = new TrackAnalytics({
53
+ platform: 'REACT_NATIVE',
54
+ App: 'CONSUMER_APP',
55
+ segment: true,
56
+ segmentKey: process.env.EXPO_PUBLIC_SEGMENT_KEY || '', //provide the segment key
57
+ devMode: __DEV__,
58
+ errorHandler: analyticsException,
59
+ });
60
+
61
+ analyticsWrapper.initAnalytics();
62
+ ```
63
+
64
+ Parameter description for TrackAnalytics class constructor
65
+
66
+ | property | value | description |
67
+ | ------------- |:-------------:| ----- |
68
+ | platfrom | `REACT_NATIVE` , `WEB`, `NODE` | this is used for internal working of analytics to |
69
+ | App | `CUSTOMER_APP`, `CUSTOMER_WEB`, `VENDOR_APP` | this property is send with all events as `fleek_platform` |
70
+ | segment | boolean | enables segment integration |
71
+ | segmentKey | string | writeKey for segment |
72
+ | devMode | boolean | if enabled, only log the event do not trigger network calls |
73
+ | debug | boolean | if enabled, triggers network calls for events when devMode is true. |
74
+ | errorHandler | function | an error handler to manage any errors thrown while initialising and sending events |
75
+
76
+ 4. Use the intialised instance in your app to send events by using the Event Names
77
+
78
+ ```ts
79
+ import { analyticsWrapper } from '../utils/track-analytics';
80
+ import { EVENT_NAMES } from 'fleek-track-analytics'
81
+
82
+ analyticsWrapper.track(EVENT_NAMES.HOME_SCREEN_VIEWED, {
83
+ customer_id: AuthInfo.getAuthData().user?.customerId,
84
+ access_country: props?.responseHeaders?.resolvedCountryCode,
85
+ })
86
+ ```
87
+
88
+ Note: Each event name is configured to have specify param type defination via `EVENT_MAP`. In the example above, if one more property is added in the parameters, the typescript will error.
89
+ How to declare events in the `EVENT_MAP` is explained here.
90
+
91
+ You can also use the base events given by segment smillarly
92
+
93
+ ```ts
94
+
95
+ analytics.identify(id , traits)
96
+
97
+ analyticsWrapper.page({ name: pageName }) // web
98
+ analyticsWrapper.screen(name, options) // react-native
99
+
100
+ ```
101
+
102
+ # How to setup for development
103
+
104
+ 1. Clone the repository
105
+
106
+ 2. Run
107
+ ```sh
108
+ yarn && yarn build
109
+
110
+ ```
111
+
112
+ 3. Login to npm with fleek credentials. (Acquire the credentials from the team members)
113
+
114
+
115
+ # How to publish changes to npm
116
+
117
+ 1. After updating the code, change the package json to a new version based on following rules
118
+ - If changes in library code upgrade as minor release patch. Example `1.1.20` to `1.2.20`
119
+ - If changes in eventmap upgrade as patch. Example `1.2.20` to `1.2.21`
120
+
121
+ 2. Build and publish
122
+ ```sh
123
+ yarn build && npm publish
124
+ ``
125
+
126
+ # How to update event map
127
+
128
+ In order to build reliability in event data consistency across platform, `.track()` function expets event name and event properties to be type defined before use. The function defination for track is hence,
129
+
130
+ ```ts
131
+ type track = <T extends EVENT_NAMES>(eventName: T, eventParams: EVENT_MAP[T]) => Promise<void> | void
132
+ ```
133
+
134
+ # How to change event map
135
+
136
+ 1. Setup the the fleek-track-analytics repo by steps given here.
137
+
138
+ 2. To add a new events, create a enum entry in EVENT_NAMES by updating `src/event-map/event-map.ts`
139
+
140
+ ```ts
141
+ // src/event-map/event-map.ts
142
+
143
+ export enum EVENT_NAMES {
144
+ HOME_SCREEN_VIEWED = 'homescreen_viewed',
145
+ PRODUCT_TILE_CLICKED = 'product_tile_clicked',
146
+ PRODUCT_DETAIL_PAGE_VIEWED = 'product_detail_page_viewed',
147
+ ADD_TO_CART = 'add_to_cart',
148
+ CART_VIEWED = 'cart_viewed',
149
+ CHECKOUT_CLICKED = 'checkout_clicked',
150
+ // add a new event name
151
+ MY_NEW_EVENT = 'my_new_event
152
+ }
153
+ ```
154
+
155
+ 3. Create a event params defination for your event in a new file in folder `src/event-map/event-data-type`
156
+
157
+ ```ts
158
+ src/event-map/event-data-types/my-new-event.ts
159
+
160
+ export interface IMyNewEvent {
161
+ id: string;
162
+ city: string,
163
+ prop1: number,
164
+ prop2: boolean
165
+ }
166
+
167
+ ```
168
+
169
+ 4. Add the mapping of event name and params in `src/event-map/event-map.ts`
170
+
171
+ ```ts
172
+ export interface EVENT_MAP {
173
+ [EVENT_NAMES.HOME_SCREEN_VIEWED]: IHomeScreenViewed;
174
+ [EVENT_NAMES.PRODUCT_TILE_CLICKED]: IProductTileClicked;
175
+ [EVENT_NAMES.PRODUCT_DETAIL_PAGE_VIEWED]: IProductDetailPageViewed;
176
+ [EVENT_NAMES.ADD_TO_CART]: IAddToCart;
177
+ [EVENT_NAMES.CART_VIEWED]: ICartViewed;
178
+ [EVENT_NAMES.CHECKOUT_CLICKED]: ICheckoutClicked;
179
+ // add mapping for MY_NEW_EVENT
180
+ [EVENT_NAMES.MY_NEW_EVENT]: IMyNewEvent
181
+ }
182
+
183
+ ```
184
+
185
+ 5. Follow the step in Releasing a new version of fleek-track-analytic section to release these changes in a new package version
186
+
187
+ 6. Upgrade the package in your application by running
188
+ ```sh
189
+ yarn upgrade fleek-track-analytics --latest
190
+ ```
191
+ 7. Post upgrade the `eventmap` will be updated and available to use (without rebuilding the app if it is already running)
192
+
193
+
@@ -0,0 +1,4 @@
1
+ export interface IMyNewEvent {
2
+ prop1: string;
3
+ prop2: number;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=my-new-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"my-new-event.js","sourceRoot":"","sources":["../../../src/event-map/event-data-types/my-new-event.ts"],"names":[],"mappings":""}
@@ -2,6 +2,7 @@ import { IAddToCart } from './event-data-types/add-to-cart';
2
2
  import { ICartViewed } from './event-data-types/cart-viewed';
3
3
  import { ICheckoutClicked } from './event-data-types/checkout-clicked';
4
4
  import { IHomeScreenViewed } from './event-data-types/home-screen-viewed';
5
+ import { IMyNewEvent } from './event-data-types/my-new-event';
5
6
  import { IProductDetailPageViewed } from './event-data-types/product-detail-page-viewed';
6
7
  import { IProductTileClicked } from './event-data-types/product-tile-clicked';
7
8
  export declare enum EVENT_NAMES {
@@ -10,7 +11,8 @@ export declare enum EVENT_NAMES {
10
11
  PRODUCT_DETAIL_PAGE_VIEWED = "product_detail_page_viewed",
11
12
  ADD_TO_CART = "add_to_cart",
12
13
  CART_VIEWED = "cart_viewed",
13
- CHECKOUT_CLICKED = "checkout_clicked"
14
+ CHECKOUT_CLICKED = "checkout_clicked",
15
+ MY_NEW_EVENT = "my_new_event"
14
16
  }
15
17
  export interface EVENT_MAP {
16
18
  [EVENT_NAMES.HOME_SCREEN_VIEWED]: IHomeScreenViewed;
@@ -19,4 +21,5 @@ export interface EVENT_MAP {
19
21
  [EVENT_NAMES.ADD_TO_CART]: IAddToCart;
20
22
  [EVENT_NAMES.CART_VIEWED]: ICartViewed;
21
23
  [EVENT_NAMES.CHECKOUT_CLICKED]: ICheckoutClicked;
24
+ [EVENT_NAMES.MY_NEW_EVENT]: IMyNewEvent;
22
25
  }
@@ -9,5 +9,6 @@ var EVENT_NAMES;
9
9
  EVENT_NAMES["ADD_TO_CART"] = "add_to_cart";
10
10
  EVENT_NAMES["CART_VIEWED"] = "cart_viewed";
11
11
  EVENT_NAMES["CHECKOUT_CLICKED"] = "checkout_clicked";
12
+ EVENT_NAMES["MY_NEW_EVENT"] = "my_new_event";
12
13
  })(EVENT_NAMES || (exports.EVENT_NAMES = EVENT_NAMES = {}));
13
14
  //# sourceMappingURL=event-map.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"event-map.js","sourceRoot":"","sources":["../../src/event-map/event-map.ts"],"names":[],"mappings":";;;AAOA,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,uDAAwC,CAAA;IACxC,4DAA6C,CAAA;IAC7C,wEAAyD,CAAA;IACzD,0CAA2B,CAAA;IAC3B,0CAA2B,CAAA;IAC3B,oDAAqC,CAAA;AACvC,CAAC,EAPW,WAAW,2BAAX,WAAW,QAOtB"}
1
+ {"version":3,"file":"event-map.js","sourceRoot":"","sources":["../../src/event-map/event-map.ts"],"names":[],"mappings":";;;AAQA,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,uDAAwC,CAAA;IACxC,4DAA6C,CAAA;IAC7C,wEAAyD,CAAA;IACzD,0CAA2B,CAAA;IAC3B,0CAA2B,CAAA;IAC3B,oDAAqC,CAAA;IACrC,4CAA6B,CAAA;AAC/B,CAAC,EARW,WAAW,2BAAX,WAAW,QAQtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleek-track-analytics",
3
- "version": "0.0.93",
3
+ "version": "0.0.94",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "exports": {