Skip to content

Commit 5512323

Browse files
author
Niall Brennan
committed
Add docs for adding a plugin to a destination plugin
1 parent 3ae14aa commit 5512323

File tree

1 file changed

+38
-0
lines changed
  • src/connections/sources/catalog/libraries/mobile/react-native

1 file changed

+38
-0
lines changed

src/connections/sources/catalog/libraries/mobile/react-native/index.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,44 @@ segmentClient.add({ plugin: new Logger() });
481481
482482
As the plugin overrides the `execute()` method, this `Logger` calls `console.log` for every event going through the Timeline.
483483
484+
### Adding a Custom Plugin to a Destination Plugin
485+
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:
486+
```js
487+
488+
import { createClient } from '@segment/analytics-react-native';
489+
490+
import {BrazePlugin} from '@segment/analytics-react-native-plugin-braze';
491+
import {BrazeEventPlugin} from './BrazeEventPlugin';
492+
493+
const segmentClient = createClient({
494+
writeKey: 'SEGMENT_KEY'
495+
});
496+
497+
const brazeplugin = new BrazePlugin();
498+
const myBrazeEventPlugin = new BrazeEventPlugin();
499+
brazeplugin.add(myBrazeEventPlugin);
500+
segmentClient.add({plugin: brazeplugin});
501+
502+
// Plugin code for BrazeEventPlugin.ts
503+
import {
504+
Plugin,
505+
PluginType,
506+
SegmentEvent,
507+
} from '@segment/analytics-react-native';
508+
509+
export class BrazeEventPlugin extends Plugin {
510+
type = PluginType.before;
511+
512+
execute(event: SegmentEvent) {
513+
var today = new Date();
514+
if (today.getDay() === 6 || today.getDay() === 0) {
515+
return event;
516+
}
517+
}
518+
}
519+
```
520+
Events will now only be passed to the Braze Destination Plugin on Saturday and Sunday based on the device time.
521+
484522
### Example Plugins
485523
These are the example plugins you can use and alter to meet your tracking needs:
486524

0 commit comments

Comments
 (0)