From 55123236006120392ae18f61214949c6e0226dc9 Mon Sep 17 00:00:00 2001 From: Niall Brennan Date: Mon, 9 Jan 2023 15:25:06 +0000 Subject: [PATCH 1/3] Add docs for adding a plugin to a destination plugin --- .../libraries/mobile/react-native/index.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/connections/sources/catalog/libraries/mobile/react-native/index.md b/src/connections/sources/catalog/libraries/mobile/react-native/index.md index 239e9889b2..2b2ca4d47c 100644 --- a/src/connections/sources/catalog/libraries/mobile/react-native/index.md +++ b/src/connections/sources/catalog/libraries/mobile/react-native/index.md @@ -481,6 +481,44 @@ segmentClient.add({ plugin: new Logger() }); As the plugin overrides the `execute()` method, this `Logger` calls `console.log` for every event going through the Timeline. +### Adding a Custom Plugin to a Destination Plugin +You can also add your own custom Plugins to Destination Plugins for custom functionality. For example, if you wished to only send events to Braze on the weekend you could implemnt the following logic: +```js + +import { createClient } from '@segment/analytics-react-native'; + +import {BrazePlugin} from '@segment/analytics-react-native-plugin-braze'; +import {BrazeEventPlugin} from './BrazeEventPlugin'; + +const segmentClient = createClient({ + writeKey: 'SEGMENT_KEY' +}); + +const brazeplugin = new BrazePlugin(); +const myBrazeEventPlugin = new BrazeEventPlugin(); +brazeplugin.add(myBrazeEventPlugin); +segmentClient.add({plugin: brazeplugin}); + +// Plugin code for BrazeEventPlugin.ts +import { + Plugin, + PluginType, + SegmentEvent, +} from '@segment/analytics-react-native'; + +export class BrazeEventPlugin extends Plugin { + type = PluginType.before; + + execute(event: SegmentEvent) { + var today = new Date(); + if (today.getDay() === 6 || today.getDay() === 0) { + return event; + } + } +} +``` +Events will now only be passed to the Braze Destination Plugin on Saturday and Sunday based on the device time. + ### Example Plugins These are the example plugins you can use and alter to meet your tracking needs: From 4c373d77a6b4bcea86694712b0ce1ad1dfc1ab6c Mon Sep 17 00:00:00 2001 From: Niall Brennan Date: Mon, 9 Jan 2023 15:32:17 +0000 Subject: [PATCH 2/3] Add docs for adding a plugin to a destination plugin --- .../sources/catalog/libraries/mobile/react-native/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connections/sources/catalog/libraries/mobile/react-native/index.md b/src/connections/sources/catalog/libraries/mobile/react-native/index.md index 2b2ca4d47c..ae34ead8bb 100644 --- a/src/connections/sources/catalog/libraries/mobile/react-native/index.md +++ b/src/connections/sources/catalog/libraries/mobile/react-native/index.md @@ -482,7 +482,7 @@ segmentClient.add({ plugin: new Logger() }); As the plugin overrides the `execute()` method, this `Logger` calls `console.log` for every event going through the Timeline. ### Adding a Custom Plugin to a Destination Plugin -You can also add your own custom Plugins to Destination Plugins for custom functionality. For example, if you wished to only send events to Braze on the weekend you could implemnt the following logic: +You can also add your own custom Plugins to Destination Plugins for custom functionality. For example, if you wished to only send events to Braze on the weekend you could implement the following logic: ```js import { createClient } from '@segment/analytics-react-native'; From f0b9a6cc38700e53bea02ba953b4327b0d6ec4f0 Mon Sep 17 00:00:00 2001 From: pwseg <86626706+pwseg@users.noreply.github.com> Date: Mon, 9 Jan 2023 20:11:07 -0600 Subject: [PATCH 3/3] Update index.md --- .../catalog/libraries/mobile/react-native/index.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/connections/sources/catalog/libraries/mobile/react-native/index.md b/src/connections/sources/catalog/libraries/mobile/react-native/index.md index ae34ead8bb..0f73842b25 100644 --- a/src/connections/sources/catalog/libraries/mobile/react-native/index.md +++ b/src/connections/sources/catalog/libraries/mobile/react-native/index.md @@ -481,8 +481,10 @@ segmentClient.add({ plugin: new Logger() }); As the plugin overrides the `execute()` method, this `Logger` calls `console.log` for every event going through the Timeline. -### Adding a Custom Plugin to a Destination Plugin -You can also add your own custom Plugins to Destination Plugins for custom functionality. For example, if you wished to only send events to Braze on the weekend you could implement the following logic: +### Add a custom Destination Plugin + +You can add custom plugins to Destination Plugins. For example, you could implement the following logic to send events to Braze on weekends only: + ```js import { createClient } from '@segment/analytics-react-native'; @@ -517,7 +519,8 @@ export class BrazeEventPlugin extends Plugin { } } ``` -Events will now only be passed to the Braze Destination Plugin on Saturday and Sunday based on the device time. + +Segment would then send events to the Braze Destination Plugin on Saturdays and Sundays, based on device time. ### Example Plugins These are the example plugins you can use and alter to meet your tracking needs: