-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(llm): add a braze plugin to segment to debounce the identify tra…
…its and reduce the data points usage
- Loading branch information
1 parent
19578f0
commit 81706ce
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"live-mobile": minor | ||
--- | ||
|
||
LLM - Add a Braze Plugin to segment to debounce the identify traits and reduce the data points usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
Plugin, | ||
PluginType, | ||
UserInfoState, | ||
SegmentEvent, | ||
EventType, | ||
} from "@segment/analytics-react-native"; | ||
import isEqual from "lodash/isEqual"; | ||
|
||
export class BrazePlugin extends Plugin { | ||
type = PluginType.before; | ||
key = "Appboy"; | ||
private lastSeenTraits: UserInfoState | undefined = undefined; | ||
|
||
execute(event: SegmentEvent): SegmentEvent | undefined { | ||
if (event.type === EventType.IdentifyEvent) { | ||
// We don't check for some traits as they are sure to be different every time | ||
const traits = { | ||
...event.traits, | ||
appTimeToInteractiveMilliseconds: undefined, | ||
stakingProvidersEnabled: undefined, | ||
}; | ||
if ( | ||
this.lastSeenTraits?.userId === event.userId && | ||
this.lastSeenTraits?.anonymousId === event.anonymousId && | ||
isEqual(this.lastSeenTraits?.traits, traits) | ||
) { | ||
const integrations = event.integrations; | ||
|
||
// If the traits didn't changed, disable braze integration | ||
if (integrations !== undefined) { | ||
integrations[this.key] = false; | ||
} | ||
} else { | ||
this.lastSeenTraits = { | ||
anonymousId: event.anonymousId ?? "", | ||
userId: event.userId, | ||
traits: traits, | ||
}; | ||
} | ||
} | ||
return event; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters