diff --git a/README.md b/README.md index 95a3de33a..3b870e95f 100644 --- a/README.md +++ b/README.md @@ -54,20 +54,12 @@ The hassle-free way to add Segment analytics to your React-Native app. Install `@segment/analytics-react-native`, [`@segment/sovran-react-native`](https://github.com/segmentio/analytics-react-native/blob/master/packages/sovran) and [`react-native-get-random-values`](https://github.com/LinusU/react-native-get-random-values): ```sh -yarn add @segment/analytics-react-native @segment/sovran-react-native react-native-get-random-values +yarn add @segment/analytics-react-native @segment/sovran-react-native react-native-get-random-values @react-native-async-storage/async-storage # or -npm install --save @segment/analytics-react-native @segment/sovran-react-native react-native-get-random-values +npm install --save @segment/analytics-react-native @segment/sovran-react-native react-native-get-random-values @react-native-async-storage/async-storage ``` -If you want to use the default persistor for the Segment Analytics client, you also have to install [`react-native-async-storage/async-storage`](https://github.com/react-native-async-storage/async-storage). - -```sh -yarn add @react-native-async-storage/async-storage -# or -npm install --save @react-native-async-storage/async-storage -``` - -*Note: If you wish to use your own persistence layer you can use the `storePersistor` option when initializing the client. Make sure you always have a persistor (either by having AsyncStorage package installed or by explicitly passing a value), else you might get unexpected sideeffects like multiple 'Application Installed' events. Read more [Client Options](#client-options)* +*Note: `@react-native-async-storage/async-storage` is an optional dependency. If you wish to use your own persistence layer you can use the `storePersistor` option when initializing the client. Make sure you always have a persistor (either by having AsyncStorage package installed or by explicitly passing a value), else you might get unexpected side-effects like multiple 'Application Installed' events. Read more [Client Options](#client-options)* For iOS, install native modules with: diff --git a/examples/E2E/plugins/ConsentManager.tsx b/examples/E2E/plugins/ConsentManager.tsx deleted file mode 100644 index eb062d230..000000000 --- a/examples/E2E/plugins/ConsentManager.tsx +++ /dev/null @@ -1,75 +0,0 @@ -import { - Plugin, - PluginType, - SegmentEvent, -} from '@segment/analytics-react-native'; - -import type {SegmentClient} from '@segment/analytics-react-native'; - -import {Alert} from 'react-native'; - -export class ConsentManager extends Plugin { - type = PluginType.before; - key = 'Consent Manager'; - - consentStatus?: boolean; - queuedEvents: SegmentEvent[] = []; - - configure(analytics: SegmentClient) { - this.analytics = analytics; - - this.showAlert(); - } - - execute(event: SegmentEvent): SegmentEvent | undefined { - if (this.consentStatus === true) { - return event; - } - if (this.consentStatus === undefined) { - this.queuedEvents.push(event); - return; - } - return; - } - - showAlert = () => { - Alert.alert( - 'Consent to Tracking', - 'Do you consent to all of the things?', - [ - { - text: 'Yes', - onPress: () => this.handleConsent(true), - style: 'cancel', - }, - { - text: 'No', - onPress: () => this.handleConsent(false), - style: 'cancel', - }, - ], - { - cancelable: true, - onDismiss: () => (this.consentStatus = undefined), - }, - ); - }; - - handleConsent(status: boolean) { - if (status === true) { - this.consentStatus = true; - this.sendQueued(); - void this.analytics?.track('Consent Authorized'); - } - if (status === false) { - this.queuedEvents = []; - } - } - - sendQueued() { - this.queuedEvents.forEach(event => { - void this.analytics?.process(event); - }); - this.queuedEvents = []; - } -} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index fc29c2697..31d588902 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -15,7 +15,7 @@ export { export { SegmentClient } from './analytics'; export { SegmentDestination } from './plugins/SegmentDestination'; export { - CategoryConsentStatusProvider, + type CategoryConsentStatusProvider, ConsentPlugin, } from './plugins/ConsentPlugin'; export * from './flushPolicies'; diff --git a/packages/core/src/plugins/ConsentPlugin.ts b/packages/core/src/plugins/ConsentPlugin.ts index 1695a8515..ef6077692 100644 --- a/packages/core/src/plugins/ConsentPlugin.ts +++ b/packages/core/src/plugins/ConsentPlugin.ts @@ -30,12 +30,16 @@ export interface CategoryConsentStatusProvider { */ export class ConsentPlugin extends Plugin { type = PluginType.before; + private consentCategoryProvider: CategoryConsentStatusProvider; + private categories: string[]; constructor( - private consentCategoryProvider: CategoryConsentStatusProvider, - private categories: string[] + consentCategoryProvider: CategoryConsentStatusProvider, + categories: string[] ) { super(); + this.consentCategoryProvider = consentCategoryProvider; + this.categories = categories; } configure(analytics: SegmentClient): void { @@ -135,9 +139,11 @@ export class ConsentPlugin extends Plugin { */ class ConsentFilterPlugin extends Plugin { type = PluginType.before; + private shouldAllowEvent: (event: SegmentEvent) => boolean; - constructor(private shouldAllowEvent: (event: SegmentEvent) => boolean) { + constructor(shouldAllowEvent: (event: SegmentEvent) => boolean) { super(); + this.shouldAllowEvent = shouldAllowEvent; } execute(event: SegmentEvent): SegmentEvent | undefined { diff --git a/packages/core/src/plugins/__tests__/consent/analytics-swift-consent b/packages/core/src/plugins/__tests__/consent/analytics-swift-consent deleted file mode 160000 index 8e23248b8..000000000 --- a/packages/core/src/plugins/__tests__/consent/analytics-swift-consent +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8e23248b87cc8b9d51139abe4a76baad896b99c7