fleek-track-analytics 0.0.2 → 0.0.3

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,8 +1,8 @@
1
1
  {
2
2
  "name": "fleek-track-analytics",
3
- "version": "0.0.2",
4
- "main": "./dist/index.js",
5
- "types": "./lin/types.d.ts",
3
+ "version": "0.0.3",
4
+ "main": "./dist/src/index.js",
5
+ "types": "./dist/src/types.d.ts",
6
6
  "repository": "https://github.com/joinfleek/fleek-track-analytics.git",
7
7
  "author": "yugalbfleek <yugal@joinfleek.com>",
8
8
  "license": "MIT",
@@ -1,36 +0,0 @@
1
- import { tAPP, tPLATFORM } from '../types';
2
- import { tToolWraperFunction } from './types';
3
-
4
- const getAnalyticsToolWrapper = async (platform: tPLATFORM) => {
5
- try {
6
- if (platform === 'REACT_NATIVE') {
7
- return (await import('./react-native-segment')).reactNativeSegment;
8
- }
9
- if (platform === 'NODE' || platform === 'WEB') {
10
- return (await import('./web-segment')).webSegment;
11
- }
12
-
13
- return null;
14
- } catch (e) {
15
- console.log(e);
16
- throw new Error(JSON.stringify(e));
17
- }
18
- };
19
-
20
- const ERROR_MESSAGES = {
21
- TOOL_INIT_FAILED_AT_LAZY_LOAD: 'TOOL_INIT_FAILED_AT_LAZY_LOAD',
22
- };
23
-
24
- export const lazyLoadTool = async (platform: tPLATFORM, app: tAPP) => {
25
- let tool = null;
26
- try {
27
- const toolWrapper: tToolWraperFunction | null = await getAnalyticsToolWrapper(platform);
28
- if (toolWrapper) {
29
- tool = await Promise.resolve(toolWrapper(app));
30
- }
31
- } catch (e) {
32
- console.error(ERROR_MESSAGES.TOOL_INIT_FAILED_AT_LAZY_LOAD, { platform, app });
33
- }
34
-
35
- return tool;
36
- };
@@ -1,28 +0,0 @@
1
- import { createClient } from '@segment/analytics-react-native';
2
- import { getSegmentKey } from './utils/getSegmentKey';
3
- import { tToolWraperFunction } from './types';
4
- import { tAPP, tTrack } from '../types';
5
-
6
- export const reactNativeSegment: tToolWraperFunction = (APP: tAPP) => {
7
- const segmentKey = getSegmentKey(APP);
8
- const client = createClient({
9
- writeKey: segmentKey,
10
- trackAppLifecycleEvents: true,
11
- });
12
-
13
- const { track, screen, identify } = client;
14
-
15
- const trackWrapper: tTrack = (eventName, eventParams) => {
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- const data = eventParams as Record<string | number, any>;
18
-
19
- track(eventName, data);
20
- };
21
-
22
- return {
23
- track: trackWrapper,
24
- screen,
25
- identify,
26
- type: 'RN_SEGMENT',
27
- };
28
- };
@@ -1,3 +0,0 @@
1
- import { IAnalyticsWrapper, tAPP } from '../types';
2
-
3
- export type tToolWraperFunction = (APP: tAPP) => IAnalyticsWrapper;
@@ -1,4 +0,0 @@
1
- import { tAPP } from '../../types';
2
-
3
- export const getSegmentKey = (APP: tAPP) => process.env[`SEGMENT_PROJECT_KEY_${APP}`] || SEGMENT_KEY_NOT_FOUND;
4
- export const SEGMENT_KEY_NOT_FOUND = 'SEGMENT_KEY_NOT_FOUND';
@@ -1,17 +0,0 @@
1
- import { getSegmentKey } from './utils/getSegmentKey';
2
- import { AnalyticsBrowser } from '@segment/analytics-next';
3
- import { tToolWraperFunction } from './types';
4
- import { tAPP } from '../types';
5
-
6
- export const webSegment: tToolWraperFunction = (APP: tAPP) => {
7
- const segmentKey = getSegmentKey(APP);
8
- const client = AnalyticsBrowser.load({ writeKey: segmentKey });
9
- const { track, page, identify } = client;
10
-
11
- return {
12
- track,
13
- screen: page,
14
- identify,
15
- type: 'WEB_SEGMENT',
16
- };
17
- };
@@ -1,28 +0,0 @@
1
- export enum EVENT_NAMES {
2
- ADD_TO_CART = 'ADD_TO_CART',
3
- }
4
-
5
- //TODO Imelement product card entity
6
- export interface ProductCartEventData {
7
- value: number;
8
- valueCurrencyCode: string;
9
- vendor: string;
10
- productCategoryL2: Array<string>;
11
- productCategoryL1: Array<string>;
12
- productGenderCategory: Array<string>;
13
- productType: string;
14
- price: number;
15
- priceCurrencyCode: string;
16
- brand: Array<string>;
17
- collectionName: Array<string>;
18
- quantity: number;
19
- productId: string;
20
- url: string;
21
- failureReason: string;
22
- productName: string;
23
- grade: string;
24
- }
25
-
26
- export interface EVENT_MAP {
27
- [EVENT_NAMES.ADD_TO_CART]: ProductCartEventData;
28
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- import { testFunction } from './init/init';
2
-
3
- testFunction();
@@ -1,16 +0,0 @@
1
- import { init } from './init';
2
-
3
- describe('init', () => {
4
- test('it returns object of type AnalyticsWrapper', async () => {
5
- expect.assertions(3);
6
- const output = await init({
7
- platform: 'REACT_NATIVE',
8
- App: 'CONSUMER_WEB',
9
- segment: true,
10
- pixel: true,
11
- });
12
- expect(output).toHaveProperty('track');
13
- expect(output).toHaveProperty('identify');
14
- expect(output).toHaveProperty('screen');
15
- });
16
- });
package/src/init/init.ts DELETED
@@ -1,36 +0,0 @@
1
- import { lazyLoadTool } from '../analytics-tool/lazy-load-tool';
2
- import { IAnalyticsWrapper, tInit } from '../types';
3
-
4
- const failedAnalyticsReurn: IAnalyticsWrapper = {
5
- track: () => {},
6
- identify: () => {},
7
- screen: () => {},
8
- type: 'FAILED_INIT',
9
- };
10
-
11
- export const init: tInit = async (params) => {
12
- console.log(params);
13
- // get right analytics-tool to get data
14
- // attach analytics type to returned object
15
- try {
16
- const analyticsWrapper = await lazyLoadTool(params.platform, params.App);
17
- if (!analyticsWrapper) {
18
- console.log('ANALYTICS_WRAPPER_NULL');
19
- }
20
- return analyticsWrapper || failedAnalyticsReurn;
21
- } catch (e) {
22
- console.log('MAIN_INIT_FAILED', JSON.stringify(e));
23
- return failedAnalyticsReurn;
24
- }
25
- };
26
-
27
- export const testFunction = async () => {
28
- console.log(
29
- await init({
30
- platform: 'REACT_NATIVE',
31
- App: 'CONSUMER_APP',
32
- segment: true,
33
- pixel: false,
34
- }),
35
- );
36
- };
package/src/types.ts DELETED
@@ -1,50 +0,0 @@
1
- import { EVENT_MAP, EVENT_NAMES } from './event-map/event-map';
2
-
3
- // [TODO] add callback for web
4
- export type tTrack = <T extends EVENT_NAMES>(eventName: T, eventParams: EVENT_MAP[T]) => void;
5
-
6
- /**
7
- * Segment React Native params type: JSONMap
8
- */
9
- export type JsonList = Array<JsonValue>;
10
- export type JsonValue = boolean | number | string | null | JsonList | JsonMap | undefined;
11
- export interface JsonMap {
12
- [key: string]: JsonValue;
13
- [index: number]: JsonValue;
14
- }
15
-
16
- /** */
17
-
18
- type tWebScreen = (
19
- category?: string,
20
- name?: string,
21
- properties?: Record<string, unknown>,
22
- options?: Record<string, unknown>,
23
- callback?: () => void,
24
- ) => void;
25
-
26
- type tRNScreen = (name: string, properties?: JsonMap) => void;
27
-
28
- export type tScreen = tWebScreen | tRNScreen;
29
-
30
- export type tPLATFORM = 'REACT_NATIVE' | 'WEB' | 'NODE';
31
-
32
- export type tAPP = 'VENDOR_APP' | 'CONSUMER_APP' | 'CONSUMER_WEB';
33
-
34
- export interface AnalyticsInit {
35
- platform: tPLATFORM;
36
- App: tAPP;
37
- segment: boolean;
38
- pixel: boolean;
39
- }
40
-
41
- export interface IAnalyticsWrapper {
42
- track: tTrack;
43
- identify: () => void;
44
- screen: tScreen;
45
- type: string;
46
- }
47
-
48
- type tInit = (params: AnalyticsInit) => Promise<IAnalyticsWrapper>;
49
-
50
- export { tInit };