@appcues/segment-react-native 0.1.0-beta1

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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Appcues
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.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @appcues/segment-react-native
2
+
3
+ `DestinationPlugin` for [Appcues](https://www.appcues.com/). Wraps [`@appcues/react-native`](https://github.com/appcues/appcues-react-native-module).
4
+
5
+ ## Installation
6
+
7
+ You need to install the `@appcues/segment-react-native` and the `@appcues/react-native` dependency.
8
+
9
+ Using NPM:
10
+ ```bash
11
+ npm install --save @appcues/segment-react-native @appcues/react-native
12
+ ```
13
+
14
+ Using Yarn:
15
+ ```bash
16
+ yarn add @appcues/segment-react-native @appcues/react-native
17
+ ```
18
+
19
+ Run `pod install` after the installation to autolink the Appcues SDK.
20
+
21
+ See [Appcues React Native Module](https://github.com/appcues/appcues-react-native-module) for more details of this dependency.
22
+ ## Usage
23
+
24
+ Follow the [instructions for adding plugins](https://github.com/segmentio/analytics-react-native#adding-plugins) on the main Analytics client:
25
+
26
+ In your code where you initialize the analytics client call the `.add(plugin)` method with an `AppcuesPlugin` instance:
27
+
28
+ ```ts
29
+ import { createClient } from '@segment/analytics-react-native';
30
+
31
+ import { AppcuesPlugin } from '@appcues/segment-react-native';
32
+
33
+ const segmentClient = createClient({
34
+ writeKey: 'SEGMENT_KEY'
35
+ });
36
+
37
+ segmentClient.add({ plugin: new AppcuesPlugin() });
38
+ ```
39
+
40
+ ## Support
41
+
42
+ Please use Github issues, Pull Requests, or feel free to reach out to our [support team](support@appcues.com).
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AppcuesPlugin = void 0;
7
+ var _analyticsReactNative = require("@segment/analytics-react-native");
8
+ var Appcues = _interopRequireWildcard(require("@appcues/react-native"));
9
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
13
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
14
+ class AppcuesPlugin extends _analyticsReactNative.DestinationPlugin {
15
+ constructor() {
16
+ super(...arguments);
17
+ _defineProperty(this, "type", _analyticsReactNative.PluginType.destination);
18
+ _defineProperty(this, "key", 'Appcues Mobile');
19
+ _defineProperty(this, "isInitialized", false);
20
+ }
21
+ async update(settings, _) {
22
+ if (this.isInitialized) {
23
+ return;
24
+ }
25
+ const appcuesSettings = settings.integrations[this.key];
26
+ if (appcuesSettings === undefined) {
27
+ return;
28
+ }
29
+ Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId).then(() => {
30
+ this.isInitialized = true;
31
+ });
32
+
33
+ // TODO: once the 3.0.0 react native plugin is released, apply the additionalAutoProperties
34
+ // here to denote in the data which usage is from this segment plugin
35
+ //
36
+ // Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId, {
37
+ // additionalAutoProperties: {
38
+ // _segmentVersion: require('@segment/analytics-react-native/package.json').version
39
+ // }
40
+ // }).then(() => { this.isInitialized = true; });
41
+ }
42
+
43
+ identify(event) {
44
+ if (this.isInitialized && event.userId != null) {
45
+ Appcues.identify(event.userId, event.traits);
46
+ }
47
+ return event;
48
+ }
49
+ track(event) {
50
+ if (this.isInitialized) {
51
+ Appcues.track(event.event, event.properties);
52
+ }
53
+ return event;
54
+ }
55
+ screen(event) {
56
+ if (this.isInitialized) {
57
+ Appcues.screen(event.name, event.properties);
58
+ }
59
+ return event;
60
+ }
61
+ group(event) {
62
+ if (this.isInitialized) {
63
+ Appcues.group(event.groupId, event.traits);
64
+ }
65
+ return event;
66
+ }
67
+ reset() {
68
+ if (this.isInitialized) {
69
+ Appcues.reset();
70
+ }
71
+ }
72
+ }
73
+ exports.AppcuesPlugin = AppcuesPlugin;
74
+ //# sourceMappingURL=AppcuesPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_analyticsReactNative","require","Appcues","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_defineProperty","value","_toPropertyKey","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","TypeError","Number","AppcuesPlugin","DestinationPlugin","constructor","arguments","PluginType","destination","update","settings","_","isInitialized","appcuesSettings","integrations","setup","accountId","applicationId","then","identify","event","userId","traits","track","properties","screen","name","group","groupId","reset","exports"],"sources":["AppcuesPlugin.ts"],"sourcesContent":["import {\n DestinationPlugin,\n PluginType,\n TrackEventType,\n ScreenEventType,\n SegmentAPISettings,\n UpdateType,\n IdentifyEventType,\n GroupEventType\n } from '@segment/analytics-react-native';\n import type { SegmentAppcuesSettings } from './types';\n import * as Appcues from '@appcues/react-native';\n \nexport class AppcuesPlugin extends DestinationPlugin { \n type = PluginType.destination;\n key = 'Appcues Mobile';\n\n private isInitialized: boolean = false;\n \n async update(settings: SegmentAPISettings, _: UpdateType) {\n if (this.isInitialized) {\n return\n }\n \n const appcuesSettings = settings.integrations[\n this.key\n ] as SegmentAppcuesSettings;\n \n if (appcuesSettings === undefined) {\n return;\n }\n\n Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId)\n .then(() => { this.isInitialized = true; });\n\n // TODO: once the 3.0.0 react native plugin is released, apply the additionalAutoProperties\n // here to denote in the data which usage is from this segment plugin\n //\n // Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId, {\n // additionalAutoProperties: {\n // _segmentVersion: require('@segment/analytics-react-native/package.json').version\n // } \n // }).then(() => { this.isInitialized = true; });\n }\n \n identify(event: IdentifyEventType) {\n if (this.isInitialized && event.userId != null) {\n Appcues.identify(event.userId, event.traits);\n }\n return event;\n }\n \n track(event: TrackEventType) { \n if (this.isInitialized) {\n Appcues.track(event.event, event.properties);\n }\n return event;\n }\n \n screen(event: ScreenEventType) {\n if (this.isInitialized) {\n Appcues.screen(event.name, event.properties);\n }\n return event;\n }\n \n group(event: GroupEventType) {\n if (this.isInitialized) {\n Appcues.group(event.groupId, event.traits);\n }\n return event;\n }\n \n reset(): void {\n if (this.isInitialized) {\n Appcues.reset()\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAWE,IAAAC,OAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAiD,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAF,wBAAAM,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GA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KA,CAACP,KAAqB,EAAE;IACzB,IAAI,IAAI,CAACR,aAAa,EAAE;MACpBnD,OAAO,CAACkE,KAAK,CAACP,KAAK,CAACQ,OAAO,EAAER,KAAK,CAACE,MAAM,CAAC;IAC9C;IACA,OAAOF,KAAK;EAChB;EAEAS,KAAKA,CAAA,EAAS;IACV,IAAI,IAAI,CAACjB,aAAa,EAAE;MACpBnD,OAAO,CAACoE,KAAK,CAAC,CAAC;IACnB;EACJ;AACJ;AAACC,OAAA,CAAA3B,aAAA,GAAAA,aAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _AppcuesPlugin = require("./AppcuesPlugin");
7
+ Object.keys(_AppcuesPlugin).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _AppcuesPlugin[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _AppcuesPlugin[key];
14
+ }
15
+ });
16
+ });
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_AppcuesPlugin","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sources":["index.ts"],"sourcesContent":["export * from './AppcuesPlugin';\n"],"mappings":";;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,cAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,cAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,cAAA,CAAAK,GAAA;IAAA;EAAA;AAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export type SegmentAppcuesSettings = {\n accountId: string;\n applicationId: string;\n };\n"],"mappings":""}
@@ -0,0 +1,65 @@
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
3
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
+ import { DestinationPlugin, PluginType } from '@segment/analytics-react-native';
5
+ import * as Appcues from '@appcues/react-native';
6
+ export class AppcuesPlugin extends DestinationPlugin {
7
+ constructor() {
8
+ super(...arguments);
9
+ _defineProperty(this, "type", PluginType.destination);
10
+ _defineProperty(this, "key", 'Appcues Mobile');
11
+ _defineProperty(this, "isInitialized", false);
12
+ }
13
+ async update(settings, _) {
14
+ if (this.isInitialized) {
15
+ return;
16
+ }
17
+ const appcuesSettings = settings.integrations[this.key];
18
+ if (appcuesSettings === undefined) {
19
+ return;
20
+ }
21
+ Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId).then(() => {
22
+ this.isInitialized = true;
23
+ });
24
+
25
+ // TODO: once the 3.0.0 react native plugin is released, apply the additionalAutoProperties
26
+ // here to denote in the data which usage is from this segment plugin
27
+ //
28
+ // Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId, {
29
+ // additionalAutoProperties: {
30
+ // _segmentVersion: require('@segment/analytics-react-native/package.json').version
31
+ // }
32
+ // }).then(() => { this.isInitialized = true; });
33
+ }
34
+
35
+ identify(event) {
36
+ if (this.isInitialized && event.userId != null) {
37
+ Appcues.identify(event.userId, event.traits);
38
+ }
39
+ return event;
40
+ }
41
+ track(event) {
42
+ if (this.isInitialized) {
43
+ Appcues.track(event.event, event.properties);
44
+ }
45
+ return event;
46
+ }
47
+ screen(event) {
48
+ if (this.isInitialized) {
49
+ Appcues.screen(event.name, event.properties);
50
+ }
51
+ return event;
52
+ }
53
+ group(event) {
54
+ if (this.isInitialized) {
55
+ Appcues.group(event.groupId, event.traits);
56
+ }
57
+ return event;
58
+ }
59
+ reset() {
60
+ if (this.isInitialized) {
61
+ Appcues.reset();
62
+ }
63
+ }
64
+ }
65
+ //# sourceMappingURL=AppcuesPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DestinationPlugin","PluginType","Appcues","AppcuesPlugin","constructor","arguments","_defineProperty","destination","update","settings","_","isInitialized","appcuesSettings","integrations","key","undefined","setup","accountId","applicationId","then","identify","event","userId","traits","track","properties","screen","name","group","groupId","reset"],"sources":["AppcuesPlugin.ts"],"sourcesContent":["import {\n DestinationPlugin,\n PluginType,\n TrackEventType,\n ScreenEventType,\n SegmentAPISettings,\n UpdateType,\n IdentifyEventType,\n GroupEventType\n } from '@segment/analytics-react-native';\n import type { SegmentAppcuesSettings } from './types';\n import * as Appcues from '@appcues/react-native';\n \nexport class AppcuesPlugin extends DestinationPlugin { \n type = PluginType.destination;\n key = 'Appcues Mobile';\n\n private isInitialized: boolean = false;\n \n async update(settings: SegmentAPISettings, _: UpdateType) {\n if (this.isInitialized) {\n return\n }\n \n const appcuesSettings = settings.integrations[\n this.key\n ] as SegmentAppcuesSettings;\n \n if (appcuesSettings === undefined) {\n return;\n }\n\n Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId)\n .then(() => { this.isInitialized = true; });\n\n // TODO: once the 3.0.0 react native plugin is released, apply the additionalAutoProperties\n // here to denote in the data which usage is from this segment plugin\n //\n // Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId, {\n // additionalAutoProperties: {\n // _segmentVersion: require('@segment/analytics-react-native/package.json').version\n // } \n // }).then(() => { this.isInitialized = true; });\n }\n \n identify(event: IdentifyEventType) {\n if (this.isInitialized && event.userId != null) {\n Appcues.identify(event.userId, event.traits);\n }\n return event;\n }\n \n track(event: TrackEventType) { \n if (this.isInitialized) {\n Appcues.track(event.event, event.properties);\n }\n return event;\n }\n \n screen(event: ScreenEventType) {\n if (this.isInitialized) {\n Appcues.screen(event.name, event.properties);\n }\n return event;\n }\n \n group(event: GroupEventType) {\n if (this.isInitialized) {\n Appcues.group(event.groupId, event.traits);\n }\n return event;\n }\n \n reset(): void {\n if (this.isInitialized) {\n Appcues.reset()\n }\n }\n}\n"],"mappings":";;;AAAA,SACIA,iBAAiB,EACjBC,UAAU,QAOL,iCAAiC;AAExC,OAAO,KAAKC,OAAO,MAAM,uBAAuB;AAElD,OAAO,MAAMC,aAAa,SAASH,iBAAiB,CAAC;EAAAI,YAAA;IAAA,SAAAC,SAAA;IAAAC,eAAA,eAC1CL,UAAU,CAACM,WAAW;IAAAD,eAAA,cACvB,gBAAgB;IAAAA,eAAA,wBAEW,KAAK;EAAA;EAEtC,MAAME,MAAMA,CAACC,QAA4B,EAAEC,CAAa,EAAE;IACtD,IAAI,IAAI,CAACC,aAAa,EAAE;MACpB;IACJ;IAEA,MAAMC,eAAe,GAAGH,QAAQ,CAACI,YAAY,CACzC,IAAI,CAACC,GAAG,CACe;IAE3B,IAAIF,eAAe,KAAKG,SAAS,EAAE;MAC/B;IACJ;IAEAb,OAAO,CAACc,KAAK,CAACJ,eAAe,CAACK,SAAS,EAAEL,eAAe,CAACM,aAAa,CAAC,CAClEC,IAAI,CAAC,MAAM;MAAE,IAAI,CAACR,aAAa,GAAG,IAAI;IAAE,CAAC,CAAC;;IAE/C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;EACJ;;EAEAS,QAAQA,CAACC,KAAwB,EAAE;IAC/B,IAAI,IAAI,CAACV,aAAa,IAAIU,KAAK,CAACC,MAAM,IAAI,IAAI,EAAE;MAC5CpB,OAAO,CAACkB,QAAQ,CAACC,KAAK,CAACC,MAAM,EAAED,KAAK,CAACE,MAAM,CAAC;IAChD;IACA,OAAOF,KAAK;EAChB;EAEAG,KAAKA,CAACH,KAAqB,EAAE;IACzB,IAAI,IAAI,CAACV,aAAa,EAAE;MACpBT,OAAO,CAACsB,KAAK,CAACH,KAAK,CAACA,KAAK,EAAEA,KAAK,CAACI,UAAU,CAAC;IAChD;IACA,OAAOJ,KAAK;EAChB;EAEAK,MAAMA,CAACL,KAAsB,EAAE;IAC3B,IAAI,IAAI,CAACV,aAAa,EAAE;MACpBT,OAAO,CAACwB,MAAM,CAACL,KAAK,CAACM,IAAI,EAAEN,KAAK,CAACI,UAAU,CAAC;IAChD;IACF,OAAOJ,KAAK;EACd;EAEAO,KAAKA,CAACP,KAAqB,EAAE;IACzB,IAAI,IAAI,CAACV,aAAa,EAAE;MACpBT,OAAO,CAAC0B,KAAK,CAACP,KAAK,CAACQ,OAAO,EAAER,KAAK,CAACE,MAAM,CAAC;IAC9C;IACA,OAAOF,KAAK;EAChB;EAEAS,KAAKA,CAAA,EAAS;IACV,IAAI,IAAI,CAACnB,aAAa,EAAE;MACpBT,OAAO,CAAC4B,KAAK,CAAC,CAAC;IACnB;EACJ;AACJ"}
@@ -0,0 +1,2 @@
1
+ export * from './AppcuesPlugin';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from './AppcuesPlugin';\n"],"mappings":"AAAA,cAAc,iBAAiB"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["export type SegmentAppcuesSettings = {\n accountId: string;\n applicationId: string;\n };\n"],"mappings":""}
@@ -0,0 +1,12 @@
1
+ import { DestinationPlugin, PluginType, TrackEventType, ScreenEventType, SegmentAPISettings, UpdateType, IdentifyEventType, GroupEventType } from '@segment/analytics-react-native';
2
+ export declare class AppcuesPlugin extends DestinationPlugin {
3
+ type: PluginType;
4
+ key: string;
5
+ private isInitialized;
6
+ update(settings: SegmentAPISettings, _: UpdateType): Promise<void>;
7
+ identify(event: IdentifyEventType): IdentifyEventType;
8
+ track(event: TrackEventType): TrackEventType;
9
+ screen(event: ScreenEventType): ScreenEventType;
10
+ group(event: GroupEventType): GroupEventType;
11
+ reset(): void;
12
+ }
@@ -0,0 +1 @@
1
+ export * from './AppcuesPlugin';
@@ -0,0 +1,4 @@
1
+ export type SegmentAppcuesSettings = {
2
+ accountId: string;
3
+ applicationId: string;
4
+ };
package/package.json ADDED
@@ -0,0 +1,121 @@
1
+ {
2
+ "name": "@appcues/segment-react-native",
3
+ "version": "0.1.0-beta1",
4
+ "description": "Segment destination plugin for Appcues.",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "!lib/typescript/example",
14
+ "!**/__tests__",
15
+ "!**/__fixtures__",
16
+ "!**/__mocks__"
17
+ ],
18
+ "scripts": {
19
+ "test": "jest",
20
+ "typescript": "tsc --noEmit",
21
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
22
+ "prepare": "bob build",
23
+ "release": "./scripts/release.sh",
24
+ "pods": "cd example && pod-install --quiet"
25
+ },
26
+ "keywords": [
27
+ "segment",
28
+ "react-native",
29
+ "ios",
30
+ "android"
31
+ ],
32
+ "repository": "https://github.com/appcues/segment-appcues-react-native",
33
+ "author": "Appcues <mobile@appcues.com> (https://www.appcues.com)",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/appcues/segment-appcues-react-native/issues"
37
+ },
38
+ "homepage": "https://github.com/appcues/segment-appcues-react-native#readme",
39
+ "publishConfig": {
40
+ "registry": "https://registry.npmjs.org/",
41
+ "access": "public"
42
+ },
43
+ "peerDependencies": {
44
+ "@segment/analytics-react-native": "*",
45
+ "@appcues/react-native": "^2.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "@babel/core": "^7.12.10",
49
+ "@babel/preset-env": "^7.1.6",
50
+ "@babel/runtime": "^7.12.5",
51
+ "@commitlint/config-conventional": "^11.0.0",
52
+ "@react-native-community/eslint-config": "^2.0.0",
53
+ "@types/jest": "^26.0.0",
54
+ "commitlint": "^11.0.0",
55
+ "eslint": "^7.2.0",
56
+ "eslint-config-prettier": "^7.0.0",
57
+ "eslint-plugin-prettier": "^3.1.3",
58
+ "husky": "^6.0.0",
59
+ "jest": "^26.0.1",
60
+ "pod-install": "^0.1.0",
61
+ "prettier": "^2.0.5",
62
+ "react-native-builder-bob": "^0.18.0",
63
+ "typescript": "^4.1.3"
64
+ },
65
+ "jest": {
66
+ "preset": "react-native",
67
+ "modulePathIgnorePatterns": [
68
+ "<rootDir>/example/node_modules",
69
+ "<rootDir>/lib/"
70
+ ]
71
+ },
72
+ "commitlint": {
73
+ "extends": [
74
+ "@commitlint/config-conventional"
75
+ ]
76
+ },
77
+ "eslintConfig": {
78
+ "root": true,
79
+ "extends": [
80
+ "@react-native-community",
81
+ "prettier"
82
+ ],
83
+ "rules": {
84
+ "prettier/prettier": [
85
+ "error",
86
+ {
87
+ "quoteProps": "consistent",
88
+ "singleQuote": true,
89
+ "tabWidth": 2,
90
+ "trailingComma": "es5",
91
+ "useTabs": false
92
+ }
93
+ ]
94
+ }
95
+ },
96
+ "eslintIgnore": [
97
+ "node_modules/",
98
+ "lib/"
99
+ ],
100
+ "prettier": {
101
+ "quoteProps": "consistent",
102
+ "singleQuote": true,
103
+ "tabWidth": 2,
104
+ "trailingComma": "es5",
105
+ "useTabs": false
106
+ },
107
+ "react-native-builder-bob": {
108
+ "source": "src",
109
+ "output": "lib",
110
+ "targets": [
111
+ "commonjs",
112
+ "module",
113
+ [
114
+ "typescript",
115
+ {
116
+ "project": "tsconfig.build.json"
117
+ }
118
+ ]
119
+ ]
120
+ }
121
+ }
@@ -0,0 +1,79 @@
1
+ import {
2
+ DestinationPlugin,
3
+ PluginType,
4
+ TrackEventType,
5
+ ScreenEventType,
6
+ SegmentAPISettings,
7
+ UpdateType,
8
+ IdentifyEventType,
9
+ GroupEventType
10
+ } from '@segment/analytics-react-native';
11
+ import type { SegmentAppcuesSettings } from './types';
12
+ import * as Appcues from '@appcues/react-native';
13
+
14
+ export class AppcuesPlugin extends DestinationPlugin {
15
+ type = PluginType.destination;
16
+ key = 'Appcues Mobile';
17
+
18
+ private isInitialized: boolean = false;
19
+
20
+ async update(settings: SegmentAPISettings, _: UpdateType) {
21
+ if (this.isInitialized) {
22
+ return
23
+ }
24
+
25
+ const appcuesSettings = settings.integrations[
26
+ this.key
27
+ ] as SegmentAppcuesSettings;
28
+
29
+ if (appcuesSettings === undefined) {
30
+ return;
31
+ }
32
+
33
+ Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId)
34
+ .then(() => { this.isInitialized = true; });
35
+
36
+ // TODO: once the 3.0.0 react native plugin is released, apply the additionalAutoProperties
37
+ // here to denote in the data which usage is from this segment plugin
38
+ //
39
+ // Appcues.setup(appcuesSettings.accountId, appcuesSettings.applicationId, {
40
+ // additionalAutoProperties: {
41
+ // _segmentVersion: require('@segment/analytics-react-native/package.json').version
42
+ // }
43
+ // }).then(() => { this.isInitialized = true; });
44
+ }
45
+
46
+ identify(event: IdentifyEventType) {
47
+ if (this.isInitialized && event.userId != null) {
48
+ Appcues.identify(event.userId, event.traits);
49
+ }
50
+ return event;
51
+ }
52
+
53
+ track(event: TrackEventType) {
54
+ if (this.isInitialized) {
55
+ Appcues.track(event.event, event.properties);
56
+ }
57
+ return event;
58
+ }
59
+
60
+ screen(event: ScreenEventType) {
61
+ if (this.isInitialized) {
62
+ Appcues.screen(event.name, event.properties);
63
+ }
64
+ return event;
65
+ }
66
+
67
+ group(event: GroupEventType) {
68
+ if (this.isInitialized) {
69
+ Appcues.group(event.groupId, event.traits);
70
+ }
71
+ return event;
72
+ }
73
+
74
+ reset(): void {
75
+ if (this.isInitialized) {
76
+ Appcues.reset()
77
+ }
78
+ }
79
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './AppcuesPlugin';
package/src/types.ts ADDED
@@ -0,0 +1,4 @@
1
+ export type SegmentAppcuesSettings = {
2
+ accountId: string;
3
+ applicationId: string;
4
+ };