fleek-track-analytics 0.0.7 → 0.0.9
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/analytics-tool/lazy-load-tool.d.ts +1 -1
- package/dist/analytics-tool/react-native-segment.js +8 -1
- package/dist/analytics-tool/react-native-segment.js.map +1 -1
- package/dist/analytics-tool/types.d.ts +2 -1
- package/dist/analytics-tool/web-segment.js +6 -1
- package/dist/analytics-tool/web-segment.js.map +1 -1
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +52 -2
- package/dist/index.js.map +1 -1
- package/dist/init/init.d.ts +1 -1
- package/dist/init/types.d.ts +32 -0
- package/dist/init/types.js +8 -0
- package/dist/init/types.js.map +1 -0
- package/dist/types.d.ts +1 -20
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { tAPP, tPLATFORM } from '../types';
|
|
2
|
-
export declare const lazyLoadTool: (platform: tPLATFORM, app: tAPP) => Promise<import("../types").IAnalyticsWrapper | null>;
|
|
2
|
+
export declare const lazyLoadTool: (platform: tPLATFORM, app: tAPP) => Promise<import("../init/types").IAnalyticsWrapper | null>;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.reactNativeSegment = void 0;
|
|
4
4
|
const analytics_react_native_1 = require("@segment/analytics-react-native");
|
|
5
5
|
const getSegmentKey_1 = require("./utils/getSegmentKey");
|
|
6
|
+
const types_1 = require("../init/types");
|
|
6
7
|
const reactNativeSegment = (APP) => {
|
|
7
8
|
const segmentKey = (0, getSegmentKey_1.getSegmentKey)(APP);
|
|
8
9
|
const client = (0, analytics_react_native_1.createClient)({
|
|
@@ -16,9 +17,15 @@ const reactNativeSegment = (APP) => {
|
|
|
16
17
|
};
|
|
17
18
|
return {
|
|
18
19
|
track: trackWrapper,
|
|
19
|
-
screen
|
|
20
|
+
screen: (params) => {
|
|
21
|
+
if (!(0, types_1.isScreenWeb)(params, 'REACT_NATIVE')) {
|
|
22
|
+
screen(params.name, params.properties);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
20
25
|
identify,
|
|
21
26
|
type: 'RN_SEGMENT',
|
|
27
|
+
segmentClient: client,
|
|
28
|
+
AnalyticsProvider: analytics_react_native_1.AnalyticsProvider,
|
|
22
29
|
};
|
|
23
30
|
};
|
|
24
31
|
exports.reactNativeSegment = reactNativeSegment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native-segment.js","sourceRoot":"","sources":["../../src/analytics-tool/react-native-segment.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"react-native-segment.js","sourceRoot":"","sources":["../../src/analytics-tool/react-native-segment.ts"],"names":[],"mappings":";;;AAAA,4EAAkF;AAClF,yDAAsD;AAGtD,yCAAoD;AAE7C,MAAM,kBAAkB,GAAwB,CAAC,GAAS,EAAE,EAAE;IACnE,MAAM,UAAU,GAAG,IAAA,6BAAa,EAAC,GAAG,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,IAAA,qCAAY,EAAC;QAC1B,QAAQ,EAAE,UAAU;QACpB,uBAAuB,EAAE,IAAI;KAC9B,CAAC,CAAC;IAEH,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAE3C,MAAM,YAAY,GAAW,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE;QAEtD,MAAM,IAAI,GAAG,WAA2C,CAAC;QAEzD,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACzB,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,IAAI,CAAC,IAAA,mBAAW,EAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;gBACzC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;QACD,QAAQ;QACR,IAAI,EAAE,YAAY;QAClB,aAAa,EAAE,MAAM;QACrB,iBAAiB,EAAE,0CAAiB;KACrC,CAAC;AACJ,CAAC,CAAC;AA5BW,QAAA,kBAAkB,sBA4B7B"}
|
|
@@ -3,13 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.webSegment = void 0;
|
|
4
4
|
const getSegmentKey_1 = require("./utils/getSegmentKey");
|
|
5
5
|
const analytics_next_1 = require("@segment/analytics-next");
|
|
6
|
+
const types_1 = require("../init/types");
|
|
6
7
|
const webSegment = (APP) => {
|
|
7
8
|
const segmentKey = (0, getSegmentKey_1.getSegmentKey)(APP);
|
|
8
9
|
const client = analytics_next_1.AnalyticsBrowser.load({ writeKey: segmentKey });
|
|
9
10
|
const { track, page, identify } = client;
|
|
10
11
|
return {
|
|
11
12
|
track,
|
|
12
|
-
screen:
|
|
13
|
+
screen: (params) => {
|
|
14
|
+
if ((0, types_1.isScreenWeb)(params, 'REACT_NATIVE')) {
|
|
15
|
+
page(params);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
13
18
|
identify,
|
|
14
19
|
type: 'WEB_SEGMENT',
|
|
15
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-segment.js","sourceRoot":"","sources":["../../src/analytics-tool/web-segment.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AACtD,4DAA2D;
|
|
1
|
+
{"version":3,"file":"web-segment.js","sourceRoot":"","sources":["../../src/analytics-tool/web-segment.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AACtD,4DAA2D;AAG3D,yCAA4C;AAErC,MAAM,UAAU,GAAwB,CAAC,GAAS,EAAE,EAAE;IAC3D,MAAM,UAAU,GAAG,IAAA,6BAAa,EAAC,GAAG,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,iCAAgB,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;IAC/D,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAEzC,OAAO;QACL,KAAK;QACL,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,IAAI,IAAA,mBAAW,EAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;gBACxC,IAAI,CAAC,MAAM,CAAC,CAAC;YACf,CAAC;QACH,CAAC;QACD,QAAQ;QACR,IAAI,EAAE,aAAa;KACpB,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,UAAU,cAerB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_MESSAGE = void 0;
|
|
4
|
+
exports.ERROR_MESSAGE = {
|
|
5
|
+
ANALYTICS_INIT_FAILED: 'ANALYTICS_INIT_FAILED',
|
|
6
|
+
ANALYTICS_CALLED_BEFORE_INIT: 'ANALYTICS_CALLED_BEFORE_INIT',
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;IAC3B,qBAAqB,EAAE,uBAAuB;IAC9C,4BAA4B,EAAE,8BAA8B;CAC7D,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
+
import { IAnalyticsInit } from './types';
|
|
2
|
+
import { IRNScreenParams, IWebScreenParams, tTrack } from './init/types';
|
|
1
3
|
export { init as trackAnalyticsInit } from './init/init';
|
|
4
|
+
declare class TrackAnalytics {
|
|
5
|
+
private initParams;
|
|
6
|
+
private analyticsWrapper;
|
|
7
|
+
constructor(params: IAnalyticsInit);
|
|
8
|
+
initAnalytics: () => Promise<void>;
|
|
9
|
+
private checkInitDone;
|
|
10
|
+
track: tTrack;
|
|
11
|
+
identify: () => void;
|
|
12
|
+
screen: (params: IWebScreenParams | IRNScreenParams) => void;
|
|
13
|
+
}
|
|
14
|
+
export default TrackAnalytics;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.trackAnalyticsInit = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const types_1 = require("./init/types");
|
|
6
|
+
const init_1 = require("./init/init");
|
|
7
|
+
var init_2 = require("./init/init");
|
|
8
|
+
Object.defineProperty(exports, "trackAnalyticsInit", { enumerable: true, get: function () { return init_2.init; } });
|
|
9
|
+
class TrackAnalytics {
|
|
10
|
+
constructor(params) {
|
|
11
|
+
this.analyticsWrapper = null;
|
|
12
|
+
this.initAnalytics = async () => {
|
|
13
|
+
try {
|
|
14
|
+
this.analyticsWrapper = await (0, init_1.init)(this.initParams);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
throw new Error(constants_1.ERROR_MESSAGE.ANALYTICS_INIT_FAILED);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
this.track = (type, params) => {
|
|
21
|
+
var _a;
|
|
22
|
+
if (this.checkInitDone()) {
|
|
23
|
+
(_a = this.analyticsWrapper) === null || _a === void 0 ? void 0 : _a.track(type, params);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
this.identify = () => {
|
|
27
|
+
var _a;
|
|
28
|
+
if (this.checkInitDone()) {
|
|
29
|
+
(_a = this.analyticsWrapper) === null || _a === void 0 ? void 0 : _a.identify();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
this.screen = (params) => {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
if (this.checkInitDone()) {
|
|
35
|
+
if ((0, types_1.isScreenWeb)(params, this.initParams.platform)) {
|
|
36
|
+
(_a = this.analyticsWrapper) === null || _a === void 0 ? void 0 : _a.screen(params);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
(_b = this.analyticsWrapper) === null || _b === void 0 ? void 0 : _b.screen(params);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
this.initParams = params;
|
|
44
|
+
}
|
|
45
|
+
checkInitDone() {
|
|
46
|
+
if (this.analyticsWrapper) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
console.error(constants_1.ERROR_MESSAGE.ANALYTICS_CALLED_BEFORE_INIT);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.default = TrackAnalytics;
|
|
6
56
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oCAAyD;AAAhD,0GAAA,IAAI,OAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAE5C,wCAAyG;AACzG,sCAAmC;AAEnC,oCAAyD;AAAhD,0GAAA,IAAI,OAAsB;AAEnC,MAAM,cAAc;IAIlB,YAAY,MAAsB;QAF1B,qBAAgB,GAA6B,IAAI,CAAC;QAM1D,kBAAa,GAAG,KAAK,IAAI,EAAE;YACzB,IAAI,CAAC;gBACH,IAAI,CAAC,gBAAgB,GAAG,MAAM,IAAA,WAAI,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACtD,CAAC;YAAC,OAAO,CAAU,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,yBAAa,CAAC,qBAAqB,CAAC,CAAC;YACvD,CAAC;QACH,CAAC,CAAC;QAWF,UAAK,GAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;;YAC/B,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;gBACzB,MAAA,IAAI,CAAC,gBAAgB,0CAAE,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC,CAAC;QAEF,aAAQ,GAAG,GAAG,EAAE;;YACd,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;gBACzB,MAAA,IAAI,CAAC,gBAAgB,0CAAE,QAAQ,EAAE,CAAC;YACpC,CAAC;QACH,CAAC,CAAC;QAEF,WAAM,GAAG,CAAC,MAA0C,EAAE,EAAE;;YACtD,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;gBACzB,IAAI,IAAA,mBAAW,EAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAClD,MAAA,IAAI,CAAC,gBAAgB,0CAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBACxC,CAAC;qBAAM,CAAC;oBACN,MAAA,IAAI,CAAC,gBAAgB,0CAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBACxC,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QAxCA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;IAC3B,CAAC;IAUO,aAAa;QACnB,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,yBAAa,CAAC,4BAA4B,CAAC,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CAuBF;AAED,kBAAe,cAAc,CAAC"}
|
package/dist/init/init.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { trackAnalyticsInit } from '
|
|
1
|
+
import { trackAnalyticsInit } from './types';
|
|
2
2
|
export declare const init: trackAnalyticsInit;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AnalyticsProvider, SegmentClient } from '@segment/analytics-react-native';
|
|
2
|
+
import { EVENT_MAP, EVENT_NAMES } from '../event-map/event-map';
|
|
3
|
+
import { IAnalyticsInit, tPLATFORM } from '../types';
|
|
4
|
+
export type tTrack = <T extends EVENT_NAMES>(eventName: T, eventParams: EVENT_MAP[T]) => void;
|
|
5
|
+
export type JsonList = Array<JsonValue>;
|
|
6
|
+
export type JsonValue = boolean | number | string | null | JsonList | JsonMap | undefined;
|
|
7
|
+
export interface JsonMap {
|
|
8
|
+
[key: string]: JsonValue;
|
|
9
|
+
[index: number]: JsonValue;
|
|
10
|
+
}
|
|
11
|
+
export interface IWebScreenParams {
|
|
12
|
+
category?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
properties?: Record<string, unknown>;
|
|
15
|
+
options?: Record<string, unknown>;
|
|
16
|
+
callback?: () => void;
|
|
17
|
+
}
|
|
18
|
+
export interface IRNScreenParams {
|
|
19
|
+
name: string;
|
|
20
|
+
properties?: JsonMap;
|
|
21
|
+
}
|
|
22
|
+
export interface IAnalyticsWrapper {
|
|
23
|
+
track: tTrack;
|
|
24
|
+
identify: () => void;
|
|
25
|
+
screen: (params: IWebScreenParams | IRNScreenParams) => void;
|
|
26
|
+
type: string;
|
|
27
|
+
segmentClient?: SegmentClient;
|
|
28
|
+
AnalyticsProvider?: typeof AnalyticsProvider;
|
|
29
|
+
}
|
|
30
|
+
export declare const isScreenWeb: (params: IWebScreenParams | IRNScreenParams, platform: tPLATFORM) => params is IWebScreenParams;
|
|
31
|
+
type tInit = (params: IAnalyticsInit) => Promise<IAnalyticsWrapper>;
|
|
32
|
+
export { tInit as trackAnalyticsInit };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isScreenWeb = void 0;
|
|
4
|
+
const isScreenWeb = (params, platform) => {
|
|
5
|
+
return params && (platform === 'WEB' || platform === 'NODE');
|
|
6
|
+
};
|
|
7
|
+
exports.isScreenWeb = isScreenWeb;
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/init/types.ts"],"names":[],"mappings":";;;AAwCO,MAAM,WAAW,GAAG,CAAC,MAA0C,EAAE,QAAmB,EAA8B,EAAE;IACzH,OAAO,MAAM,IAAI,CAAC,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,MAAM,CAAC,CAAC;AAC/D,CAAC,CAAC;AAFW,QAAA,WAAW,eAEtB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
import { EVENT_MAP, EVENT_NAMES } from './event-map/event-map';
|
|
2
|
-
export type tTrack = <T extends EVENT_NAMES>(eventName: T, eventParams: EVENT_MAP[T]) => void;
|
|
3
|
-
export type JsonList = Array<JsonValue>;
|
|
4
|
-
export type JsonValue = boolean | number | string | null | JsonList | JsonMap | undefined;
|
|
5
|
-
export interface JsonMap {
|
|
6
|
-
[key: string]: JsonValue;
|
|
7
|
-
[index: number]: JsonValue;
|
|
8
|
-
}
|
|
9
|
-
type tWebScreen = (category?: string, name?: string, properties?: Record<string, unknown>, options?: Record<string, unknown>, callback?: () => void) => void;
|
|
10
|
-
type tRNScreen = (name: string, properties?: JsonMap) => void;
|
|
11
|
-
export type tScreen = tWebScreen | tRNScreen;
|
|
12
1
|
export type tPLATFORM = 'REACT_NATIVE' | 'WEB' | 'NODE';
|
|
13
2
|
export type tAPP = 'VENDOR_APP' | 'CONSUMER_APP' | 'CONSUMER_WEB';
|
|
14
|
-
export interface
|
|
3
|
+
export interface IAnalyticsInit {
|
|
15
4
|
platform: tPLATFORM;
|
|
16
5
|
App: tAPP;
|
|
17
6
|
segment: boolean;
|
|
18
7
|
pixel: boolean;
|
|
19
8
|
}
|
|
20
|
-
export interface IAnalyticsWrapper {
|
|
21
|
-
track: tTrack;
|
|
22
|
-
identify: () => void;
|
|
23
|
-
screen: tScreen;
|
|
24
|
-
type: string;
|
|
25
|
-
}
|
|
26
|
-
type tInit = (params: AnalyticsInit) => Promise<IAnalyticsWrapper>;
|
|
27
|
-
export { tInit as trackAnalyticsInit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleek-track-analytics",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lint": "eslint --ignore-path .gitignore src/**/*.ts",
|
|
15
15
|
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
|
|
16
16
|
"test": "jest --passWithNoTests",
|
|
17
|
-
"build": "tsc",
|
|
17
|
+
"build": "rm -rf dist && tsc",
|
|
18
18
|
"prepublish": "lint && build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|