fleek-track-analytics 0.0.2 → 0.0.4
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 +2 -0
- package/dist/analytics-tool/lazy-load-tool.js +59 -0
- package/dist/analytics-tool/lazy-load-tool.js.map +1 -0
- package/dist/analytics-tool/react-native-segment.d.ts +2 -0
- package/dist/analytics-tool/react-native-segment.js +25 -0
- package/dist/analytics-tool/react-native-segment.js.map +1 -0
- package/{src/analytics-tool/types.ts → dist/analytics-tool/types.d.ts} +0 -1
- package/dist/analytics-tool/types.js +3 -0
- package/dist/analytics-tool/types.js.map +1 -0
- package/dist/analytics-tool/utils/getSegmentKey.d.ts +3 -0
- package/dist/analytics-tool/utils/getSegmentKey.js +7 -0
- package/dist/analytics-tool/utils/getSegmentKey.js.map +1 -0
- package/dist/analytics-tool/web-segment.d.ts +2 -0
- package/dist/analytics-tool/web-segment.js +18 -0
- package/dist/analytics-tool/web-segment.js.map +1 -0
- package/dist/event-map/event-map.d.ts +25 -0
- package/dist/event-map/event-map.js +8 -0
- package/dist/event-map/event-map.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/init/init.d.ts +3 -0
- package/dist/init/init.js +35 -0
- package/dist/init/init.js.map +1 -0
- package/dist/init/init.test.d.ts +1 -0
- package/dist/init/init.test.js +18 -0
- package/dist/init/init.test.js.map +1 -0
- package/{src/types.ts → dist/types.d.ts} +11 -34
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +2 -2
- package/tsconfig.json +1 -1
- package/src/analytics-tool/lazy-load-tool.ts +0 -36
- package/src/analytics-tool/react-native-segment.ts +0 -28
- package/src/analytics-tool/utils/getSegmentKey.ts +0 -4
- package/src/analytics-tool/web-segment.ts +0 -17
- package/src/event-map/event-map.ts +0 -28
- package/src/index.ts +0 -3
- package/src/init/init.test.ts +0 -16
- package/src/init/init.ts +0 -36
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.lazyLoadTool = void 0;
|
|
27
|
+
const getAnalyticsToolWrapper = async (platform) => {
|
|
28
|
+
try {
|
|
29
|
+
if (platform === 'REACT_NATIVE') {
|
|
30
|
+
return (await Promise.resolve().then(() => __importStar(require('./react-native-segment')))).reactNativeSegment;
|
|
31
|
+
}
|
|
32
|
+
if (platform === 'NODE' || platform === 'WEB') {
|
|
33
|
+
return (await Promise.resolve().then(() => __importStar(require('./web-segment')))).webSegment;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
console.log(e);
|
|
39
|
+
throw new Error(JSON.stringify(e));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const ERROR_MESSAGES = {
|
|
43
|
+
TOOL_INIT_FAILED_AT_LAZY_LOAD: 'TOOL_INIT_FAILED_AT_LAZY_LOAD',
|
|
44
|
+
};
|
|
45
|
+
const lazyLoadTool = async (platform, app) => {
|
|
46
|
+
let tool = null;
|
|
47
|
+
try {
|
|
48
|
+
const toolWrapper = await getAnalyticsToolWrapper(platform);
|
|
49
|
+
if (toolWrapper) {
|
|
50
|
+
tool = await Promise.resolve(toolWrapper(app));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.error(ERROR_MESSAGES.TOOL_INIT_FAILED_AT_LAZY_LOAD, { platform, app });
|
|
55
|
+
}
|
|
56
|
+
return tool;
|
|
57
|
+
};
|
|
58
|
+
exports.lazyLoadTool = lazyLoadTool;
|
|
59
|
+
//# sourceMappingURL=lazy-load-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-load-tool.js","sourceRoot":"","sources":["../../src/analytics-tool/lazy-load-tool.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,uBAAuB,GAAG,KAAK,EAAE,QAAmB,EAAE,EAAE;IAC5D,IAAI,CAAC;QACH,IAAI,QAAQ,KAAK,cAAc,EAAE,CAAC;YAChC,OAAO,CAAC,wDAAa,wBAAwB,GAAC,CAAC,CAAC,kBAAkB,CAAC;QACrE,CAAC;QACD,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;YAC9C,OAAO,CAAC,wDAAa,eAAe,GAAC,CAAC,CAAC,UAAU,CAAC;QACpD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG;IACrB,6BAA6B,EAAE,+BAA+B;CAC/D,CAAC;AAEK,MAAM,YAAY,GAAG,KAAK,EAAE,QAAmB,EAAE,GAAS,EAAE,EAAE;IACnE,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,WAAW,GAA+B,MAAM,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QACxF,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,6BAA6B,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reactNativeSegment = void 0;
|
|
4
|
+
const analytics_react_native_1 = require("@segment/analytics-react-native");
|
|
5
|
+
const getSegmentKey_1 = require("./utils/getSegmentKey");
|
|
6
|
+
const reactNativeSegment = (APP) => {
|
|
7
|
+
const segmentKey = (0, getSegmentKey_1.getSegmentKey)(APP);
|
|
8
|
+
const client = (0, analytics_react_native_1.createClient)({
|
|
9
|
+
writeKey: segmentKey,
|
|
10
|
+
trackAppLifecycleEvents: true,
|
|
11
|
+
});
|
|
12
|
+
const { track, screen, identify } = client;
|
|
13
|
+
const trackWrapper = (eventName, eventParams) => {
|
|
14
|
+
const data = eventParams;
|
|
15
|
+
track(eventName, data);
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
track: trackWrapper,
|
|
19
|
+
screen,
|
|
20
|
+
identify,
|
|
21
|
+
type: 'RN_SEGMENT',
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.reactNativeSegment = reactNativeSegment;
|
|
25
|
+
//# sourceMappingURL=react-native-segment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native-segment.js","sourceRoot":"","sources":["../../src/analytics-tool/react-native-segment.ts"],"names":[],"mappings":";;;AAAA,4EAA+D;AAC/D,yDAAsD;AAI/C,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;QACN,QAAQ;QACR,IAAI,EAAE,YAAY;KACnB,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,kBAAkB,sBAsB7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/analytics-tool/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SEGMENT_KEY_NOT_FOUND = exports.getSegmentKey = void 0;
|
|
4
|
+
const getSegmentKey = (APP) => process.env[`SEGMENT_PROJECT_KEY_${APP}`] || exports.SEGMENT_KEY_NOT_FOUND;
|
|
5
|
+
exports.getSegmentKey = getSegmentKey;
|
|
6
|
+
exports.SEGMENT_KEY_NOT_FOUND = 'SEGMENT_KEY_NOT_FOUND';
|
|
7
|
+
//# sourceMappingURL=getSegmentKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSegmentKey.js","sourceRoot":"","sources":["../../../src/analytics-tool/utils/getSegmentKey.ts"],"names":[],"mappings":";;;AAEO,MAAM,aAAa,GAAG,CAAC,GAAS,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,EAAE,CAAC,IAAI,6BAAqB,CAAC;AAAlG,QAAA,aAAa,iBAAqF;AAClG,QAAA,qBAAqB,GAAG,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webSegment = void 0;
|
|
4
|
+
const getSegmentKey_1 = require("./utils/getSegmentKey");
|
|
5
|
+
const analytics_next_1 = require("@segment/analytics-next");
|
|
6
|
+
const webSegment = (APP) => {
|
|
7
|
+
const segmentKey = (0, getSegmentKey_1.getSegmentKey)(APP);
|
|
8
|
+
const client = analytics_next_1.AnalyticsBrowser.load({ writeKey: segmentKey });
|
|
9
|
+
const { track, page, identify } = client;
|
|
10
|
+
return {
|
|
11
|
+
track,
|
|
12
|
+
screen: page,
|
|
13
|
+
identify,
|
|
14
|
+
type: 'WEB_SEGMENT',
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.webSegment = webSegment;
|
|
18
|
+
//# sourceMappingURL=web-segment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-segment.js","sourceRoot":"","sources":["../../src/analytics-tool/web-segment.ts"],"names":[],"mappings":";;;AAAA,yDAAsD;AACtD,4DAA2D;AAIpD,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,IAAI;QACZ,QAAQ;QACR,IAAI,EAAE,aAAa;KACpB,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,UAAU,cAWrB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare enum EVENT_NAMES {
|
|
2
|
+
ADD_TO_CART = "ADD_TO_CART"
|
|
3
|
+
}
|
|
4
|
+
export interface ProductCartEventData {
|
|
5
|
+
value: number;
|
|
6
|
+
valueCurrencyCode: string;
|
|
7
|
+
vendor: string;
|
|
8
|
+
productCategoryL2: Array<string>;
|
|
9
|
+
productCategoryL1: Array<string>;
|
|
10
|
+
productGenderCategory: Array<string>;
|
|
11
|
+
productType: string;
|
|
12
|
+
price: number;
|
|
13
|
+
priceCurrencyCode: string;
|
|
14
|
+
brand: Array<string>;
|
|
15
|
+
collectionName: Array<string>;
|
|
16
|
+
quantity: number;
|
|
17
|
+
productId: string;
|
|
18
|
+
url: string;
|
|
19
|
+
failureReason: string;
|
|
20
|
+
productName: string;
|
|
21
|
+
grade: string;
|
|
22
|
+
}
|
|
23
|
+
export interface EVENT_MAP {
|
|
24
|
+
[EVENT_NAMES.ADD_TO_CART]: ProductCartEventData;
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVENT_NAMES = void 0;
|
|
4
|
+
var EVENT_NAMES;
|
|
5
|
+
(function (EVENT_NAMES) {
|
|
6
|
+
EVENT_NAMES["ADD_TO_CART"] = "ADD_TO_CART";
|
|
7
|
+
})(EVENT_NAMES || (exports.EVENT_NAMES = EVENT_NAMES = {}));
|
|
8
|
+
//# sourceMappingURL=event-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-map.js","sourceRoot":"","sources":["../../src/event-map/event-map.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,0CAA2B,CAAA;AAC7B,CAAC,EAFW,WAAW,2BAAX,WAAW,QAEtB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,sCAA2C;AAE3C,IAAA,mBAAY,GAAE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testFunction = exports.init = void 0;
|
|
4
|
+
const lazy_load_tool_1 = require("../analytics-tool/lazy-load-tool");
|
|
5
|
+
const failedAnalyticsReurn = {
|
|
6
|
+
track: () => { },
|
|
7
|
+
identify: () => { },
|
|
8
|
+
screen: () => { },
|
|
9
|
+
type: 'FAILED_INIT',
|
|
10
|
+
};
|
|
11
|
+
const init = async (params) => {
|
|
12
|
+
console.log(params);
|
|
13
|
+
try {
|
|
14
|
+
const analyticsWrapper = await (0, lazy_load_tool_1.lazyLoadTool)(params.platform, params.App);
|
|
15
|
+
if (!analyticsWrapper) {
|
|
16
|
+
console.log('ANALYTICS_WRAPPER_NULL');
|
|
17
|
+
}
|
|
18
|
+
return analyticsWrapper || failedAnalyticsReurn;
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
console.log('MAIN_INIT_FAILED', JSON.stringify(e));
|
|
22
|
+
return failedAnalyticsReurn;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.init = init;
|
|
26
|
+
const testFunction = async () => {
|
|
27
|
+
console.log(await (0, exports.init)({
|
|
28
|
+
platform: 'REACT_NATIVE',
|
|
29
|
+
App: 'CONSUMER_APP',
|
|
30
|
+
segment: true,
|
|
31
|
+
pixel: false,
|
|
32
|
+
}));
|
|
33
|
+
};
|
|
34
|
+
exports.testFunction = testFunction;
|
|
35
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/init/init.ts"],"names":[],"mappings":";;;AAAA,qEAAgE;AAGhE,MAAM,oBAAoB,GAAsB;IAC9C,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;IACf,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;IAChB,IAAI,EAAE,aAAa;CACpB,CAAC;AAEK,MAAM,IAAI,GAAU,KAAK,EAAE,MAAM,EAAE,EAAE;IAC1C,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAGpB,IAAI,CAAC;QACH,MAAM,gBAAgB,GAAG,MAAM,IAAA,6BAAY,EAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;QACzE,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,gBAAgB,IAAI,oBAAoB,CAAC;IAClD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACnD,OAAO,oBAAoB,CAAC;IAC9B,CAAC;AACH,CAAC,CAAC;AAdW,QAAA,IAAI,QAcf;AAEK,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;IACrC,OAAO,CAAC,GAAG,CACT,MAAM,IAAA,YAAI,EAAC;QACT,QAAQ,EAAE,cAAc;QACxB,GAAG,EAAE,cAAc;QACnB,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,KAAK;KACb,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,YAAY,gBASvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const init_1 = require("./init");
|
|
4
|
+
describe('init', () => {
|
|
5
|
+
test('it returns object of type AnalyticsWrapper', async () => {
|
|
6
|
+
expect.assertions(3);
|
|
7
|
+
const output = await (0, init_1.init)({
|
|
8
|
+
platform: 'REACT_NATIVE',
|
|
9
|
+
App: 'CONSUMER_WEB',
|
|
10
|
+
segment: true,
|
|
11
|
+
pixel: true,
|
|
12
|
+
});
|
|
13
|
+
expect(output).toHaveProperty('track');
|
|
14
|
+
expect(output).toHaveProperty('identify');
|
|
15
|
+
expect(output).toHaveProperty('screen');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=init.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.test.js","sourceRoot":"","sources":["../../src/init/init.test.ts"],"names":[],"mappings":";;AAAA,iCAA8B;AAE9B,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,IAAI,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACrB,MAAM,MAAM,GAAG,MAAM,IAAA,WAAI,EAAC;YACxB,QAAQ,EAAE,cAAc;YACxB,GAAG,EAAE,cAAc;YACnB,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QAC1C,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,50 +1,27 @@
|
|
|
1
1
|
import { EVENT_MAP, EVENT_NAMES } from './event-map/event-map';
|
|
2
|
-
|
|
3
|
-
// [TODO] add callback for web
|
|
4
2
|
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
3
|
export type JsonList = Array<JsonValue>;
|
|
10
4
|
export type JsonValue = boolean | number | string | null | JsonList | JsonMap | undefined;
|
|
11
5
|
export interface JsonMap {
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
[key: string]: JsonValue;
|
|
7
|
+
[index: number]: JsonValue;
|
|
14
8
|
}
|
|
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
|
-
|
|
9
|
+
type tWebScreen = (category?: string, name?: string, properties?: Record<string, unknown>, options?: Record<string, unknown>, callback?: () => void) => void;
|
|
26
10
|
type tRNScreen = (name: string, properties?: JsonMap) => void;
|
|
27
|
-
|
|
28
11
|
export type tScreen = tWebScreen | tRNScreen;
|
|
29
|
-
|
|
30
12
|
export type tPLATFORM = 'REACT_NATIVE' | 'WEB' | 'NODE';
|
|
31
|
-
|
|
32
13
|
export type tAPP = 'VENDOR_APP' | 'CONSUMER_APP' | 'CONSUMER_WEB';
|
|
33
|
-
|
|
34
14
|
export interface AnalyticsInit {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
platform: tPLATFORM;
|
|
16
|
+
App: tAPP;
|
|
17
|
+
segment: boolean;
|
|
18
|
+
pixel: boolean;
|
|
39
19
|
}
|
|
40
|
-
|
|
41
20
|
export interface IAnalyticsWrapper {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
track: tTrack;
|
|
22
|
+
identify: () => void;
|
|
23
|
+
screen: tScreen;
|
|
24
|
+
type: string;
|
|
46
25
|
}
|
|
47
|
-
|
|
48
26
|
type tInit = (params: AnalyticsInit) => Promise<IAnalyticsWrapper>;
|
|
49
|
-
|
|
50
27
|
export { tInit };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleek-track-analytics",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
|
-
"types": "./
|
|
5
|
+
"types": "./dist/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",
|
package/tsconfig.json
CHANGED
|
@@ -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,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
package/src/init/init.test.ts
DELETED
|
@@ -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
|
-
};
|