Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66c35ed

Browse files
authored
Merge pull request segmentio#4014 from segmentio/niall/add_plugin_rn_info
Add docs for adding a plugin to a destination plugin
2 parents 6a69a0a + f0b9a6c commit 66c35ed

File tree

1 file changed

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

1 file changed

+41
-0
lines changed

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

+41
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,47 @@ 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+
### Add a custom Destination Plugin
485+
486+
You can add custom plugins to Destination Plugins. For example, you could implement the following logic to send events to Braze on weekends only:
487+
488+
```js
489+
490+
import { createClient } from '@segment/analytics-react-native';
491+
492+
import {BrazePlugin} from '@segment/analytics-react-native-plugin-braze';
493+
import {BrazeEventPlugin} from './BrazeEventPlugin';
494+
495+
const segmentClient = createClient({
496+
writeKey: 'SEGMENT_KEY'
497+
});
498+
499+
const brazeplugin = new BrazePlugin();
500+
const myBrazeEventPlugin = new BrazeEventPlugin();
501+
brazeplugin.add(myBrazeEventPlugin);
502+
segmentClient.add({plugin: brazeplugin});
503+
504+
// Plugin code for BrazeEventPlugin.ts
505+
import {
506+
Plugin,
507+
PluginType,
508+
SegmentEvent,
509+
} from '@segment/analytics-react-native';
510+
511+
export class BrazeEventPlugin extends Plugin {
512+
type = PluginType.before;
513+
514+
execute(event: SegmentEvent) {
515+
var today = new Date();
516+
if (today.getDay() === 6 || today.getDay() === 0) {
517+
return event;
518+
}
519+
}
520+
}
521+
```
522+
523+
Segment would then send events to the Braze Destination Plugin on Saturdays and Sundays, based on device time.
524+
484525
### Example Plugins
485526
These are the example plugins you can use and alter to meet your tracking needs:
486527

0 commit comments

Comments
 (0)