@amplitude/plugin-experiment-react-native 1.0.0-beta.0
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 +21 -0
- package/README.md +52 -0
- package/lib/commonjs/experiment.js +42 -0
- package/lib/commonjs/experiment.js.map +1 -0
- package/lib/commonjs/index.js +19 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/version.js +9 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/experiment.js +35 -0
- package/lib/module/experiment.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/experiment.d.ts +21 -0
- package/lib/typescript/experiment.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +2 -0
- package/lib/typescript/version.d.ts.map +1 -0
- package/package.json +80 -0
- package/src/experiment.ts +36 -0
- package/src/index.ts +2 -0
- package/src/version.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Amplitude Analytics
|
|
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,52 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://amplitude.com" target="_blank" align="center">
|
|
3
|
+
<img src="https://static.amplitude.com/lightning/46c85bfd91905de8047f1ee65c7c93d6fa9ee6ea/static/media/amplitude-logo-with-text.4fb9e463.svg" width="280">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# @amplitude/plugin-experiment-react-native
|
|
8
|
+
|
|
9
|
+
Official React Native Analytics plugin for Amplitude Experiment integration.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @amplitude/analytics-react-native @amplitude/plugin-experiment-react-native
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Create the plugin, add it to the React Native Analytics client, and initialize Analytics. The Experiment client is
|
|
20
|
+
available on the plugin after Analytics initialization completes.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { add, init } from '@amplitude/analytics-react-native';
|
|
24
|
+
import { experimentPlugin } from '@amplitude/plugin-experiment-react-native';
|
|
25
|
+
|
|
26
|
+
const experiment = experimentPlugin({
|
|
27
|
+
deploymentKey: 'DEPLOYMENT_KEY', // Optional when Experiment and Analytics use the same project key.
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
await add(experiment).promise;
|
|
31
|
+
await init('AMPLITUDE_API_KEY').promise;
|
|
32
|
+
|
|
33
|
+
await experiment.experiment?.start();
|
|
34
|
+
const variant = experiment.experiment?.variant('experiment-key');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The plugin accepts all options from `ExperimentConfig` in `@amplitude/experiment-react-native-client`, plus:
|
|
38
|
+
|
|
39
|
+
| Name | Type | Default | Description |
|
|
40
|
+
| --- | --- | --- | --- |
|
|
41
|
+
| `deploymentKey` | `string` | Analytics API key | The deployment key for Amplitude Experiment. |
|
|
42
|
+
|
|
43
|
+
By default, `serverZone` and `instanceName` are inherited from the Analytics client so Experiment identity and exposure
|
|
44
|
+
events use the same Analytics instance. Explicit Experiment configuration takes precedence.
|
|
45
|
+
|
|
46
|
+
## Integration behavior
|
|
47
|
+
|
|
48
|
+
The plugin uses `Experiment.initializeWithAmplitudeAnalytics`, which connects Experiment to the Analytics identity store
|
|
49
|
+
and event bridge. It does not duplicate identity or exposure tracking logic. Removing the plugin stops the Experiment
|
|
50
|
+
client.
|
|
51
|
+
|
|
52
|
+
For more information, see the [Amplitude Experiment React Native SDK documentation](https://amplitude.com/docs/sdks/experiment-sdks/experiment-react-native).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.experimentPlugin = exports.ExperimentPlugin = void 0;
|
|
7
|
+
var _experimentReactNativeClient = require("@amplitude/experiment-react-native-client");
|
|
8
|
+
/**
|
|
9
|
+
* Experiment configuration with an optional deployment key.
|
|
10
|
+
* Falls back to the Analytics project API key when a deployment key is not provided.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
class ExperimentPlugin {
|
|
14
|
+
static pluginName = '@amplitude/experiment-analytics-plugin';
|
|
15
|
+
name = ExperimentPlugin.pluginName;
|
|
16
|
+
type = 'enrichment';
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
}
|
|
20
|
+
async setup(config, _client) {
|
|
21
|
+
const {
|
|
22
|
+
deploymentKey,
|
|
23
|
+
...experimentOptions
|
|
24
|
+
} = this.config ?? {};
|
|
25
|
+
if (experimentOptions.serverZone === undefined && config.serverZone !== undefined) {
|
|
26
|
+
experimentOptions.serverZone = config.serverZone;
|
|
27
|
+
}
|
|
28
|
+
if (experimentOptions.instanceName === undefined && config.instanceName !== undefined) {
|
|
29
|
+
experimentOptions.instanceName = config.instanceName;
|
|
30
|
+
}
|
|
31
|
+
this.experiment = _experimentReactNativeClient.Experiment.initializeWithAmplitudeAnalytics(deploymentKey || config.apiKey, experimentOptions);
|
|
32
|
+
}
|
|
33
|
+
async teardown() {
|
|
34
|
+
var _this$experiment;
|
|
35
|
+
(_this$experiment = this.experiment) === null || _this$experiment === void 0 || _this$experiment.stop();
|
|
36
|
+
this.experiment = undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ExperimentPlugin = ExperimentPlugin;
|
|
40
|
+
const experimentPlugin = config => new ExperimentPlugin(config);
|
|
41
|
+
exports.experimentPlugin = experimentPlugin;
|
|
42
|
+
//# sourceMappingURL=experiment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_experimentReactNativeClient","require","ExperimentPlugin","pluginName","name","type","constructor","config","setup","_client","deploymentKey","experimentOptions","serverZone","undefined","instanceName","experiment","Experiment","initializeWithAmplitudeAnalytics","apiKey","teardown","_this$experiment","stop","exports","experimentPlugin"],"sourceRoot":"../../src","sources":["experiment.ts"],"mappings":";;;;;;AACA,IAAAA,4BAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;;AAGO,MAAMC,gBAAgB,CAAmE;EAC9F,OAAOC,UAAU,GAAG,wCAAwC;EAC5DC,IAAI,GAAGF,gBAAgB,CAACC,UAAU;EAClCE,IAAI,GAAG,YAAY;EAGnBC,WAAWA,CAAQC,MAA+B,EAAE;IAAA,KAAjCA,MAA+B,GAA/BA,MAA+B;EAAG;EAErD,MAAMC,KAAKA,CAACD,MAAyB,EAAEE,OAA0B,EAAiB;IAChF,MAAM;MAAEC,aAAa;MAAE,GAAGC;IAAkB,CAAC,GAAG,IAAI,CAACJ,MAAM,IAAI,CAAC,CAAC;IACjE,IAAII,iBAAiB,CAACC,UAAU,KAAKC,SAAS,IAAIN,MAAM,CAACK,UAAU,KAAKC,SAAS,EAAE;MACjFF,iBAAiB,CAACC,UAAU,GAAGL,MAAM,CAACK,UAAU;IAClD;IACA,IAAID,iBAAiB,CAACG,YAAY,KAAKD,SAAS,IAAIN,MAAM,CAACO,YAAY,KAAKD,SAAS,EAAE;MACrFF,iBAAiB,CAACG,YAAY,GAAGP,MAAM,CAACO,YAAY;IACtD;IACA,IAAI,CAACC,UAAU,GAAGC,uCAAU,CAACC,gCAAgC,CAACP,aAAa,IAAIH,MAAM,CAACW,MAAM,EAAEP,iBAAiB,CAAC;EAClH;EAEA,MAAMQ,QAAQA,CAAA,EAAkB;IAAA,IAAAC,gBAAA;IAC9B,CAAAA,gBAAA,OAAI,CAACL,UAAU,cAAAK,gBAAA,eAAfA,gBAAA,CAAiBC,IAAI,CAAC,CAAC;IACvB,IAAI,CAACN,UAAU,GAAGF,SAAS;EAC7B;AACF;AAACS,OAAA,CAAApB,gBAAA,GAAAA,gBAAA;AAEM,MAAMqB,gBAAgB,GAAIhB,MAA+B,IAAuB,IAAIL,gBAAgB,CAACK,MAAM,CAAC;AAACe,OAAA,CAAAC,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ExperimentPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _experiment.ExperimentPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "experimentPlugin", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _experiment.experimentPlugin;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _experiment = require("./experiment");
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_experiment","require"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["VERSION","exports"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Experiment } from '@amplitude/experiment-react-native-client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Experiment configuration with an optional deployment key.
|
|
5
|
+
* Falls back to the Analytics project API key when a deployment key is not provided.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class ExperimentPlugin {
|
|
9
|
+
static pluginName = '@amplitude/experiment-analytics-plugin';
|
|
10
|
+
name = ExperimentPlugin.pluginName;
|
|
11
|
+
type = 'enrichment';
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
async setup(config, _client) {
|
|
16
|
+
const {
|
|
17
|
+
deploymentKey,
|
|
18
|
+
...experimentOptions
|
|
19
|
+
} = this.config ?? {};
|
|
20
|
+
if (experimentOptions.serverZone === undefined && config.serverZone !== undefined) {
|
|
21
|
+
experimentOptions.serverZone = config.serverZone;
|
|
22
|
+
}
|
|
23
|
+
if (experimentOptions.instanceName === undefined && config.instanceName !== undefined) {
|
|
24
|
+
experimentOptions.instanceName = config.instanceName;
|
|
25
|
+
}
|
|
26
|
+
this.experiment = Experiment.initializeWithAmplitudeAnalytics(deploymentKey || config.apiKey, experimentOptions);
|
|
27
|
+
}
|
|
28
|
+
async teardown() {
|
|
29
|
+
var _this$experiment;
|
|
30
|
+
(_this$experiment = this.experiment) === null || _this$experiment === void 0 || _this$experiment.stop();
|
|
31
|
+
this.experiment = undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const experimentPlugin = config => new ExperimentPlugin(config);
|
|
35
|
+
//# sourceMappingURL=experiment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Experiment","ExperimentPlugin","pluginName","name","type","constructor","config","setup","_client","deploymentKey","experimentOptions","serverZone","undefined","instanceName","experiment","initializeWithAmplitudeAnalytics","apiKey","teardown","_this$experiment","stop","experimentPlugin"],"sourceRoot":"../../src","sources":["experiment.ts"],"mappings":"AACA,SAASA,UAAU,QAAQ,2CAA2C;;AAGtE;AACA;AACA;AACA;;AAGA,OAAO,MAAMC,gBAAgB,CAAmE;EAC9F,OAAOC,UAAU,GAAG,wCAAwC;EAC5DC,IAAI,GAAGF,gBAAgB,CAACC,UAAU;EAClCE,IAAI,GAAG,YAAY;EAGnBC,WAAWA,CAAQC,MAA+B,EAAE;IAAA,KAAjCA,MAA+B,GAA/BA,MAA+B;EAAG;EAErD,MAAMC,KAAKA,CAACD,MAAyB,EAAEE,OAA0B,EAAiB;IAChF,MAAM;MAAEC,aAAa;MAAE,GAAGC;IAAkB,CAAC,GAAG,IAAI,CAACJ,MAAM,IAAI,CAAC,CAAC;IACjE,IAAII,iBAAiB,CAACC,UAAU,KAAKC,SAAS,IAAIN,MAAM,CAACK,UAAU,KAAKC,SAAS,EAAE;MACjFF,iBAAiB,CAACC,UAAU,GAAGL,MAAM,CAACK,UAAU;IAClD;IACA,IAAID,iBAAiB,CAACG,YAAY,KAAKD,SAAS,IAAIN,MAAM,CAACO,YAAY,KAAKD,SAAS,EAAE;MACrFF,iBAAiB,CAACG,YAAY,GAAGP,MAAM,CAACO,YAAY;IACtD;IACA,IAAI,CAACC,UAAU,GAAGd,UAAU,CAACe,gCAAgC,CAACN,aAAa,IAAIH,MAAM,CAACU,MAAM,EAAEN,iBAAiB,CAAC;EAClH;EAEA,MAAMO,QAAQA,CAAA,EAAkB;IAAA,IAAAC,gBAAA;IAC9B,CAAAA,gBAAA,OAAI,CAACJ,UAAU,cAAAI,gBAAA,eAAfA,gBAAA,CAAiBC,IAAI,CAAC,CAAC;IACvB,IAAI,CAACL,UAAU,GAAGF,SAAS;EAC7B;AACF;AAEA,OAAO,MAAMQ,gBAAgB,GAAId,MAA+B,IAAuB,IAAIL,gBAAgB,CAACK,MAAM,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ExperimentPlugin","experimentPlugin"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,gBAAgB,QAAqC,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["VERSION"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EnrichmentPlugin, ReactNativeClient, ReactNativeConfig } from '@amplitude/analytics-core';
|
|
2
|
+
import type { ExperimentConfig, Client as IExperimentClient } from '@amplitude/experiment-react-native-client';
|
|
3
|
+
/**
|
|
4
|
+
* Experiment configuration with an optional deployment key.
|
|
5
|
+
* Falls back to the Analytics project API key when a deployment key is not provided.
|
|
6
|
+
*/
|
|
7
|
+
export type ExperimentPluginConfig = ExperimentConfig & {
|
|
8
|
+
deploymentKey?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class ExperimentPlugin implements EnrichmentPlugin<ReactNativeClient, ReactNativeConfig> {
|
|
11
|
+
config?: ExperimentPluginConfig | undefined;
|
|
12
|
+
static pluginName: string;
|
|
13
|
+
name: string;
|
|
14
|
+
type: "enrichment";
|
|
15
|
+
experiment?: IExperimentClient;
|
|
16
|
+
constructor(config?: ExperimentPluginConfig | undefined);
|
|
17
|
+
setup(config: ReactNativeConfig, _client: ReactNativeClient): Promise<void>;
|
|
18
|
+
teardown(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare const experimentPlugin: (config?: ExperimentPluginConfig) => ExperimentPlugin;
|
|
21
|
+
//# sourceMappingURL=experiment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"experiment.d.ts","sourceRoot":"","sources":["../../src/experiment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAExG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAE/G;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,GAAG;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnF,qBAAa,gBAAiB,YAAW,gBAAgB,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAM1E,MAAM,CAAC;IAL1B,MAAM,CAAC,UAAU,SAA4C;IAC7D,IAAI,SAA+B;IACnC,IAAI,eAAyB;IAC7B,UAAU,CAAC,EAAE,iBAAiB,CAAC;gBAEZ,MAAM,CAAC,oCAAwB;IAE5C,KAAK,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAW3E,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAIhC;AAED,eAAO,MAAM,gBAAgB,YAAa,sBAAsB,KAAG,gBAAgD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC/F,YAAY,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,2CAA2C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amplitude/plugin-experiment-react-native",
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
|
+
"description": "Amplitude Experiment plugin for React Native Analytics",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"analytics",
|
|
7
|
+
"amplitude",
|
|
8
|
+
"experiment",
|
|
9
|
+
"react-native"
|
|
10
|
+
],
|
|
11
|
+
"author": "Amplitude Inc",
|
|
12
|
+
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "lib/commonjs/index",
|
|
15
|
+
"module": "lib/module/index",
|
|
16
|
+
"types": "lib/typescript/index.d.ts",
|
|
17
|
+
"react-native": "src/index",
|
|
18
|
+
"source": "src/index",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"tag": "latest"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/amplitude/Amplitude-TypeScript.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"src",
|
|
33
|
+
"lib",
|
|
34
|
+
"!test",
|
|
35
|
+
"!**/__tests__",
|
|
36
|
+
"!**/__fixtures__",
|
|
37
|
+
"!**/__mocks__"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@amplitude/experiment-react-native-client": "^1.8.0",
|
|
41
|
+
"@amplitude/analytics-core": "2.55.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"react": "18.2.0",
|
|
45
|
+
"react-native": "0.73.0",
|
|
46
|
+
"react-native-builder-bob": "^0.20.3"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": "*",
|
|
50
|
+
"react-native": "*"
|
|
51
|
+
},
|
|
52
|
+
"react-native-builder-bob": {
|
|
53
|
+
"source": "src",
|
|
54
|
+
"output": "lib",
|
|
55
|
+
"targets": [
|
|
56
|
+
"commonjs",
|
|
57
|
+
"module",
|
|
58
|
+
[
|
|
59
|
+
"typescript",
|
|
60
|
+
{
|
|
61
|
+
"project": "tsconfig.build.json"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "bob build",
|
|
68
|
+
"clean": "rimraf node_modules lib coverage",
|
|
69
|
+
"fix": "pnpm fix:eslint & pnpm fix:prettier",
|
|
70
|
+
"fix:eslint": "eslint '{src,test}/**/*.ts' --fix",
|
|
71
|
+
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
|
|
72
|
+
"lint": "pnpm lint:eslint & pnpm lint:prettier",
|
|
73
|
+
"lint:eslint": "eslint '{src,test}/**/*.ts'",
|
|
74
|
+
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
|
|
75
|
+
"test": "jest",
|
|
76
|
+
"typecheck": "tsc --noEmit -p ./tsconfig.json",
|
|
77
|
+
"version": "pnpm version-file && pnpm build",
|
|
78
|
+
"version-file": "node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { EnrichmentPlugin, ReactNativeClient, ReactNativeConfig } from '@amplitude/analytics-core';
|
|
2
|
+
import { Experiment } from '@amplitude/experiment-react-native-client';
|
|
3
|
+
import type { ExperimentConfig, Client as IExperimentClient } from '@amplitude/experiment-react-native-client';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Experiment configuration with an optional deployment key.
|
|
7
|
+
* Falls back to the Analytics project API key when a deployment key is not provided.
|
|
8
|
+
*/
|
|
9
|
+
export type ExperimentPluginConfig = ExperimentConfig & { deploymentKey?: string };
|
|
10
|
+
|
|
11
|
+
export class ExperimentPlugin implements EnrichmentPlugin<ReactNativeClient, ReactNativeConfig> {
|
|
12
|
+
static pluginName = '@amplitude/experiment-analytics-plugin';
|
|
13
|
+
name = ExperimentPlugin.pluginName;
|
|
14
|
+
type = 'enrichment' as const;
|
|
15
|
+
experiment?: IExperimentClient;
|
|
16
|
+
|
|
17
|
+
constructor(public config?: ExperimentPluginConfig) {}
|
|
18
|
+
|
|
19
|
+
async setup(config: ReactNativeConfig, _client: ReactNativeClient): Promise<void> {
|
|
20
|
+
const { deploymentKey, ...experimentOptions } = this.config ?? {};
|
|
21
|
+
if (experimentOptions.serverZone === undefined && config.serverZone !== undefined) {
|
|
22
|
+
experimentOptions.serverZone = config.serverZone;
|
|
23
|
+
}
|
|
24
|
+
if (experimentOptions.instanceName === undefined && config.instanceName !== undefined) {
|
|
25
|
+
experimentOptions.instanceName = config.instanceName;
|
|
26
|
+
}
|
|
27
|
+
this.experiment = Experiment.initializeWithAmplitudeAnalytics(deploymentKey || config.apiKey, experimentOptions);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async teardown(): Promise<void> {
|
|
31
|
+
this.experiment?.stop();
|
|
32
|
+
this.experiment = undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const experimentPlugin = (config?: ExperimentPluginConfig): ExperimentPlugin => new ExperimentPlugin(config);
|
package/src/index.ts
ADDED
package/src/version.ts
ADDED