@ht-sdks/events-sdk-react-native-plugin-clevertap 1.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/LICENSE ADDED
@@ -0,0 +1,45 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Hightouch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ MIT License
26
+
27
+ Copyright (c) 2020 Segment
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy
30
+ of this software and associated documentation files (the "Software"), to deal
31
+ in the Software without restriction, including without limitation the rights
32
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33
+ copies of the Software, and to permit persons to whom the Software is
34
+ furnished to do so, subject to the following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be included in all
37
+ copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+ SOFTWARE.
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ClevertapPlugin = void 0;
7
+ var _eventsSdkReactNative = require("@ht-sdks/events-sdk-react-native");
8
+ var _parameterMapping = require("./parameterMapping");
9
+ var _clevertapReactNative = _interopRequireDefault(require("clevertap-react-native"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ const mappedTraits = (0, _eventsSdkReactNative.generateMapTransform)(_parameterMapping.mapTraits, _parameterMapping.transformMap);
12
+ class ClevertapPlugin extends _eventsSdkReactNative.DestinationPlugin {
13
+ type = _eventsSdkReactNative.PluginType.destination;
14
+ key = 'CleverTap';
15
+ identify(event) {
16
+ const traits = event.traits;
17
+ const safeTraits = mappedTraits(traits);
18
+ const userId = event.userId ?? event.anonymousId;
19
+ if (safeTraits.DOB !== undefined && safeTraits.DOB !== null && !(safeTraits.DOB instanceof Date)) {
20
+ if (typeof safeTraits.DOB === 'string' || typeof safeTraits.DOB === 'number') {
21
+ const birthday = new Date(safeTraits.DOB);
22
+ if (birthday !== undefined && birthday !== null && !isNaN(birthday.getTime())) {
23
+ safeTraits.DOB = birthday;
24
+ }
25
+ } else {
26
+ delete safeTraits.DOB;
27
+ this.analytics?.logger.warn(`Birthday found "${event.traits?.birthday}" could not be parsed as a Date. Try converting to ISO format.`);
28
+ }
29
+ }
30
+ const clevertapTraits = {
31
+ ...safeTraits,
32
+ Identity: userId
33
+ };
34
+ _clevertapReactNative.default.profileSet(clevertapTraits);
35
+ return event;
36
+ }
37
+ track(event) {
38
+ if (event.event === 'Order Completed') {
39
+ const userId = event.userId ?? event.anonymousId;
40
+ const {
41
+ products = [],
42
+ ...props
43
+ } = event.properties ?? {};
44
+ const chargeDetails = {
45
+ ...props,
46
+ Identity: userId
47
+ };
48
+ const sanitizedProducts = products ?? [];
49
+ _clevertapReactNative.default.recordChargedEvent(chargeDetails, sanitizedProducts);
50
+ } else {
51
+ _clevertapReactNative.default.recordEvent(event.event, event.properties);
52
+ }
53
+ return event;
54
+ }
55
+ screen(event) {
56
+ const screenName = event.name ?? 'Screen Viewed';
57
+ const userId = event.userId ?? event.anonymousId;
58
+ const screenProps = {
59
+ ...event.properties,
60
+ Identity: userId
61
+ };
62
+ _clevertapReactNative.default.recordEvent(screenName, screenProps);
63
+ return event;
64
+ }
65
+ }
66
+ exports.ClevertapPlugin = ClevertapPlugin;
67
+ //# sourceMappingURL=ClevertapPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_eventsSdkReactNative","require","_parameterMapping","_clevertapReactNative","_interopRequireDefault","obj","__esModule","default","mappedTraits","generateMapTransform","mapTraits","transformMap","ClevertapPlugin","DestinationPlugin","type","PluginType","destination","key","identify","event","traits","safeTraits","userId","anonymousId","DOB","undefined","Date","birthday","isNaN","getTime","analytics","logger","warn","clevertapTraits","Identity","CleverTap","profileSet","track","products","props","properties","chargeDetails","sanitizedProducts","recordChargedEvent","recordEvent","screen","screenName","name","screenProps","exports"],"sourceRoot":"../../src","sources":["ClevertapPlugin.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AASA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA+C,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAA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kB,KAAKA,CAAClB,KAAqB,EAAE;IAC3B,IAAIA,KAAK,CAACA,KAAK,KAAK,iBAAiB,EAAE;MACrC,MAAMG,MAAM,GAAGH,KAAK,CAACG,MAAM,IAAIH,KAAK,CAACI,WAAW;MAChD,MAAM;QAAEe,QAAQ,GAAG,EAAE;QAAE,GAAGC;MAAM,CAAC,GAAGpB,KAAK,CAACqB,UAAU,IAAI,CAAC,CAAC;MAC1D,MAAMC,aAAa,GAAG;QAAE,GAAGF,KAAK;QAAEL,QAAQ,EAAEZ;MAAO,CAAC;MACpD,MAAMoB,iBAAiB,GAAGJ,QAAQ,IAAI,EAAE;MAExCH,6BAAS,CAACQ,kBAAkB,CAACF,aAAa,EAAEC,iBAAiB,CAAC;IAChE,CAAC,MAAM;MACLP,6BAAS,CAACS,WAAW,CAACzB,KAAK,CAACA,KAAK,EAAEA,KAAK,CAACqB,UAAU,CAAC;IACtD;IACA,OAAOrB,KAAK;EACd;EAEA0B,MAAMA,CAAC1B,KAAsB,EAAE;IAC7B,MAAM2B,UAAU,GAAG3B,KAAK,CAAC4B,IAAI,IAAI,eAAe;IAChD,MAAMzB,MAAM,GAAGH,KAAK,CAACG,MAAM,IAAIH,KAAK,CAACI,WAAW;IAChD,MAAMyB,WAAW,GAAG;MAAE,GAAG7B,KAAK,CAACqB,UAAU;MAAEN,QAAQ,EAAEZ;IAAO,CAAC;IAE7Da,6BAAS,CAACS,WAAW,CAACE,UAAU,EAAEE,WAAW,CAAC;IAC9C,OAAO7B,KAAK;EACd;AACF;AAAC8B,OAAA,CAAArC,eAAA,GAAAA,eAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _ClevertapPlugin = require("./ClevertapPlugin");
7
+ Object.keys(_ClevertapPlugin).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _ClevertapPlugin[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _ClevertapPlugin[key];
14
+ }
15
+ });
16
+ });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_ClevertapPlugin","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,gBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,gBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,gBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.transformMap = exports.mapTraits = void 0;
7
+ const mapTraits = exports.mapTraits = {
8
+ name: 'Name',
9
+ birthday: 'DOB',
10
+ avatar: 'Photo',
11
+ gender: 'Gender',
12
+ phone: 'Phone',
13
+ email: 'Email'
14
+ };
15
+ const transformMap = exports.transformMap = {
16
+ event: value => {
17
+ if (typeof value === 'string') {
18
+ if (value in mapTraits) {
19
+ return mapTraits[value];
20
+ }
21
+ }
22
+ return value;
23
+ }
24
+ };
25
+ //# sourceMappingURL=parameterMapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mapTraits","exports","name","birthday","avatar","gender","phone","email","transformMap","event","value"],"sourceRoot":"../../src","sources":["parameterMapping.ts"],"mappings":";;;;;;AAAO,MAAMA,SAAoC,GAAAC,OAAA,CAAAD,SAAA,GAAG;EAClDE,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,KAAK;EACfC,MAAM,EAAE,OAAO;EACfC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;AACT,CAAC;AAEM,MAAMC,YAA4D,GAAAP,OAAA,CAAAO,YAAA,GAAG;EAC1EC,KAAK,EAAGC,KAAc,IAAK;IACzB,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B,IAAIA,KAAK,IAAIV,SAAS,EAAE;QACtB,OAAOA,SAAS,CAACU,KAAK,CAAC;MACzB;IACF;IACA,OAAOA,KAAK;EACd;AACF,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { DestinationPlugin, PluginType, generateMapTransform } from '@ht-sdks/events-sdk-react-native';
2
+ import { mapTraits, transformMap } from './parameterMapping';
3
+ import CleverTap from 'clevertap-react-native';
4
+ const mappedTraits = generateMapTransform(mapTraits, transformMap);
5
+ export class ClevertapPlugin extends DestinationPlugin {
6
+ type = PluginType.destination;
7
+ key = 'CleverTap';
8
+ identify(event) {
9
+ const traits = event.traits;
10
+ const safeTraits = mappedTraits(traits);
11
+ const userId = event.userId ?? event.anonymousId;
12
+ if (safeTraits.DOB !== undefined && safeTraits.DOB !== null && !(safeTraits.DOB instanceof Date)) {
13
+ if (typeof safeTraits.DOB === 'string' || typeof safeTraits.DOB === 'number') {
14
+ const birthday = new Date(safeTraits.DOB);
15
+ if (birthday !== undefined && birthday !== null && !isNaN(birthday.getTime())) {
16
+ safeTraits.DOB = birthday;
17
+ }
18
+ } else {
19
+ delete safeTraits.DOB;
20
+ this.analytics?.logger.warn(`Birthday found "${event.traits?.birthday}" could not be parsed as a Date. Try converting to ISO format.`);
21
+ }
22
+ }
23
+ const clevertapTraits = {
24
+ ...safeTraits,
25
+ Identity: userId
26
+ };
27
+ CleverTap.profileSet(clevertapTraits);
28
+ return event;
29
+ }
30
+ track(event) {
31
+ if (event.event === 'Order Completed') {
32
+ const userId = event.userId ?? event.anonymousId;
33
+ const {
34
+ products = [],
35
+ ...props
36
+ } = event.properties ?? {};
37
+ const chargeDetails = {
38
+ ...props,
39
+ Identity: userId
40
+ };
41
+ const sanitizedProducts = products ?? [];
42
+ CleverTap.recordChargedEvent(chargeDetails, sanitizedProducts);
43
+ } else {
44
+ CleverTap.recordEvent(event.event, event.properties);
45
+ }
46
+ return event;
47
+ }
48
+ screen(event) {
49
+ const screenName = event.name ?? 'Screen Viewed';
50
+ const userId = event.userId ?? event.anonymousId;
51
+ const screenProps = {
52
+ ...event.properties,
53
+ Identity: userId
54
+ };
55
+ CleverTap.recordEvent(screenName, screenProps);
56
+ return event;
57
+ }
58
+ }
59
+ //# sourceMappingURL=ClevertapPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DestinationPlugin","PluginType","generateMapTransform","mapTraits","transformMap","CleverTap","mappedTraits","ClevertapPlugin","type","destination","key","identify","event","traits","safeTraits","userId","anonymousId","DOB","undefined","Date","birthday","isNaN","getTime","analytics","logger","warn","clevertapTraits","Identity","profileSet","track","products","props","properties","chargeDetails","sanitizedProducts","recordChargedEvent","recordEvent","screen","screenName","name","screenProps"],"sourceRoot":"../../src","sources":["ClevertapPlugin.ts"],"mappings":"AAAA,SACEA,iBAAiB,EACjBC,UAAU,EAIVC,oBAAoB,QACf,kCAAkC;AAEzC,SAASC,SAAS,EAAEC,YAAY,QAAQ,oBAAoB;AAC5D,OAAOC,SAAS,MAAM,wBAAwB;AAC9C,MAAMC,YAAY,GAAGJ,oBAAoB,CAACC,SAAS,EAAEC,YAAY,CAAC;AAElE,OAAO,MAAMG,eAAe,SAASP,iBAAiB,CAAC;EACrDQ,IAAI,GAAGP,UAAU,CAACQ,WAAW;EAC7BC,GAAG,GAAG,WAAW;EAEjBC,QAAQA,CAACC,KAAwB,EAAE;IACjC,MAAMC,MAAM,GAAGD,KAAK,CAACC,MAAiC;IACtD,MAAMC,UAAU,GAAGR,YAAY,CAACO,MAAM,CAAC;IACvC,MAAME,MAAM,GAAGH,KAAK,CAACG,MAAM,IAAIH,KAAK,CAACI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B,CAACF,aAAa,EAAEC,iBAAiB,CAAC;IAChE,CAAC,MAAM;MACL7B,SAAS,CAAC+B,WAAW,CAACxB,KAAK,CAACA,KAAK,EAAEA,KAAK,CAACoB,UAAU,CAAC;IACtD;IACA,OAAOpB,KAAK;EACd;EAEAyB,MAAMA,CAACzB,KAAsB,EAAE;IAC7B,MAAM0B,UAAU,GAAG1B,KAAK,CAAC2B,IAAI,IAAI,eAAe;IAChD,MAAMxB,MAAM,GAAGH,KAAK,CAACG,MAAM,IAAIH,KAAK,CAACI,WAAW;IAChD,MAAMwB,WAAW,GAAG;MAAE,GAAG5B,KAAK,CAACoB,UAAU;MAAEL,QAAQ,EAAEZ;IAAO,CAAC;IAE7DV,SAAS,CAAC+B,WAAW,CAACE,UAAU,EAAEE,WAAW,CAAC;IAC9C,OAAO5B,KAAK;EACd;AACF"}
@@ -0,0 +1,2 @@
1
+ export * from './ClevertapPlugin';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,cAAc,mBAAmB"}
@@ -0,0 +1,19 @@
1
+ export const mapTraits = {
2
+ name: 'Name',
3
+ birthday: 'DOB',
4
+ avatar: 'Photo',
5
+ gender: 'Gender',
6
+ phone: 'Phone',
7
+ email: 'Email'
8
+ };
9
+ export const transformMap = {
10
+ event: value => {
11
+ if (typeof value === 'string') {
12
+ if (value in mapTraits) {
13
+ return mapTraits[value];
14
+ }
15
+ }
16
+ return value;
17
+ }
18
+ };
19
+ //# sourceMappingURL=parameterMapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mapTraits","name","birthday","avatar","gender","phone","email","transformMap","event","value"],"sourceRoot":"../../src","sources":["parameterMapping.ts"],"mappings":"AAAA,OAAO,MAAMA,SAAoC,GAAG;EAClDC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE,KAAK;EACfC,MAAM,EAAE,OAAO;EACfC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;AACT,CAAC;AAED,OAAO,MAAMC,YAA4D,GAAG;EAC1EC,KAAK,EAAGC,KAAc,IAAK;IACzB,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MAC7B,IAAIA,KAAK,IAAIT,SAAS,EAAE;QACtB,OAAOA,SAAS,CAACS,KAAK,CAAC;MACzB;IACF;IACA,OAAOA,KAAK;EACd;AACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { DestinationPlugin, PluginType, TrackEventType, ScreenEventType, IdentifyEventType } from '@ht-sdks/events-sdk-react-native';
2
+ export declare class ClevertapPlugin extends DestinationPlugin {
3
+ type: PluginType;
4
+ key: string;
5
+ identify(event: IdentifyEventType): IdentifyEventType;
6
+ track(event: TrackEventType): TrackEventType;
7
+ screen(event: ScreenEventType): ScreenEventType;
8
+ }
9
+ //# sourceMappingURL=ClevertapPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClevertapPlugin.d.ts","sourceRoot":"","sources":["../../../src/ClevertapPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,eAAe,EACf,iBAAiB,EAElB,MAAM,kCAAkC,CAAC;AAM1C,qBAAa,eAAgB,SAAQ,iBAAiB;IACpD,IAAI,aAA0B;IAC9B,GAAG,SAAe;IAElB,QAAQ,CAAC,KAAK,EAAE,iBAAiB;IAmCjC,KAAK,CAAC,KAAK,EAAE,cAAc;IAc3B,MAAM,CAAC,KAAK,EAAE,eAAe;CAQ9B"}
@@ -0,0 +1,2 @@
1
+ export * from './ClevertapPlugin';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const mapTraits: {
2
+ [key: string]: string;
3
+ };
4
+ export declare const transformMap: {
5
+ [key: string]: (value: unknown) => unknown;
6
+ };
7
+ //# sourceMappingURL=parameterMapping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameterMapping.d.ts","sourceRoot":"","sources":["../../../src/parameterMapping.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAO9C,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAA;CAStE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@ht-sdks/events-sdk-react-native-plugin-clevertap",
3
+ "version": "1.0.4",
4
+ "description": "The hassle-free way to add Hightouch analytics to your React-Native app.",
5
+ "main": "lib/commonjs/index",
6
+ "scripts": {
7
+ "build": "bob build",
8
+ "test": "jest",
9
+ "typescript": "tsc --noEmit",
10
+ "clean": "rimraf lib node_modules"
11
+ },
12
+ "keywords": [
13
+ "hightouch",
14
+ "react-native",
15
+ "ios",
16
+ "android"
17
+ ],
18
+ "module": "lib/module/index",
19
+ "types": "lib/typescript/src/index.d.ts",
20
+ "react-native": "src/index",
21
+ "source": "src/index",
22
+ "files": [
23
+ "src",
24
+ "lib",
25
+ "android",
26
+ "ios",
27
+ "cpp",
28
+ "hightouch-events-sdk-react-native.podspec",
29
+ "package.json",
30
+ "!src/**/*.e2e.mock.js",
31
+ "!**/__tests__",
32
+ "!**/__fixtures__",
33
+ "!**/__mocks__"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/ht-sdks/events-sdk-react-native.git",
38
+ "directory": "packages/core"
39
+ },
40
+ "author": "Hightouch <hello@hightouch.com> (https://hightouch.com/)",
41
+ "license": "MIT",
42
+ "bugs": {
43
+ "url": "https://github.com/ht-sdks/events-sdk-react-native/issues"
44
+ },
45
+ "homepage": "https://github.com/ht-sdks/events-sdk-react-native#readme",
46
+ "peerDependencies": {
47
+ "@ht-sdks/events-sdk-react-native": "^2.18.2",
48
+ "clevertap-react-native": "^1.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@ht-sdks/analytics-rn-shared": "workspace:^",
52
+ "@ht-sdks/events-sdk-react-native": "^2.18.2",
53
+ "@ht-sdks/sovran-react-native": "^1.1.1",
54
+ "clevertap-react-native": "^1.0.0",
55
+ "jest": "^29.7.0",
56
+ "react-native-builder-bob": "^0.23.1",
57
+ "rimraf": "^5.0.5",
58
+ "typescript": "^5.2.2"
59
+ },
60
+ "react-native-builder-bob": {
61
+ "source": "src",
62
+ "output": "lib",
63
+ "targets": [
64
+ "commonjs",
65
+ "module",
66
+ "typescript"
67
+ ]
68
+ },
69
+ "engines": {
70
+ "node": ">=12"
71
+ }
72
+ }
@@ -0,0 +1,75 @@
1
+ import {
2
+ DestinationPlugin,
3
+ PluginType,
4
+ TrackEventType,
5
+ ScreenEventType,
6
+ IdentifyEventType,
7
+ generateMapTransform,
8
+ } from '@ht-sdks/events-sdk-react-native';
9
+
10
+ import { mapTraits, transformMap } from './parameterMapping';
11
+ import CleverTap from 'clevertap-react-native';
12
+ const mappedTraits = generateMapTransform(mapTraits, transformMap);
13
+
14
+ export class ClevertapPlugin extends DestinationPlugin {
15
+ type = PluginType.destination;
16
+ key = 'CleverTap';
17
+
18
+ identify(event: IdentifyEventType) {
19
+ const traits = event.traits as Record<string, unknown>;
20
+ const safeTraits = mappedTraits(traits);
21
+ const userId = event.userId ?? event.anonymousId;
22
+
23
+ if (
24
+ safeTraits.DOB !== undefined &&
25
+ safeTraits.DOB !== null &&
26
+ !(safeTraits.DOB instanceof Date)
27
+ ) {
28
+ if (
29
+ typeof safeTraits.DOB === 'string' ||
30
+ typeof safeTraits.DOB === 'number'
31
+ ) {
32
+ const birthday = new Date(safeTraits.DOB);
33
+ if (
34
+ birthday !== undefined &&
35
+ birthday !== null &&
36
+ !isNaN(birthday.getTime())
37
+ ) {
38
+ safeTraits.DOB = birthday;
39
+ }
40
+ } else {
41
+ delete safeTraits.DOB;
42
+
43
+ this.analytics?.logger.warn(
44
+ `Birthday found "${event.traits?.birthday}" could not be parsed as a Date. Try converting to ISO format.`
45
+ );
46
+ }
47
+ }
48
+ const clevertapTraits = { ...safeTraits, Identity: userId };
49
+ CleverTap.profileSet(clevertapTraits);
50
+ return event;
51
+ }
52
+
53
+ track(event: TrackEventType) {
54
+ if (event.event === 'Order Completed') {
55
+ const userId = event.userId ?? event.anonymousId;
56
+ const { products = [], ...props } = event.properties ?? {};
57
+ const chargeDetails = { ...props, Identity: userId };
58
+ const sanitizedProducts = products ?? [];
59
+
60
+ CleverTap.recordChargedEvent(chargeDetails, sanitizedProducts);
61
+ } else {
62
+ CleverTap.recordEvent(event.event, event.properties);
63
+ }
64
+ return event;
65
+ }
66
+
67
+ screen(event: ScreenEventType) {
68
+ const screenName = event.name ?? 'Screen Viewed';
69
+ const userId = event.userId ?? event.anonymousId;
70
+ const screenProps = { ...event.properties, Identity: userId };
71
+
72
+ CleverTap.recordEvent(screenName, screenProps);
73
+ return event;
74
+ }
75
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './ClevertapPlugin';
@@ -0,0 +1,19 @@
1
+ export const mapTraits: { [key: string]: string } = {
2
+ name: 'Name',
3
+ birthday: 'DOB',
4
+ avatar: 'Photo',
5
+ gender: 'Gender',
6
+ phone: 'Phone',
7
+ email: 'Email',
8
+ };
9
+
10
+ export const transformMap: { [key: string]: (value: unknown) => unknown } = {
11
+ event: (value: unknown) => {
12
+ if (typeof value === 'string') {
13
+ if (value in mapTraits) {
14
+ return mapTraits[value];
15
+ }
16
+ }
17
+ return value;
18
+ },
19
+ };