Skip to content

Commit

Permalink
feat: add MetaMetrics custom flush vars and log (#8787)
Browse files Browse the repository at this point in the history
- add optional custom flush vars and log in MetaMetrics Segment client
config
- update example .js.env

Fixes #8772
  • Loading branch information
NicolasMassart authored Mar 1, 2024
1 parent 108da1c commit 330f415
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .js.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ export SEGMENT_WRITE_KEY=""
export SEGMENT_PROXY_URL=""
export SEGMENT_DELETE_API_SOURCE_ID=""
export SEGMENT_REGULATIONS_ENDPOINT=""

# Optional for dev purpose: Segment flush interval in seconds
# example for 1 second flush interval
export SEGMENT_FLUSH_INTERVAL="1"
# example for flush when 1 event is queued
export SEGMENT_FLUSH_EVENT_LIMIT="1"
15 changes: 15 additions & 0 deletions app/core/Analytics/MetaMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,22 @@ class MetaMetrics implements IMetaMetrics {
proxy: process.env.SEGMENT_PROXY_URL as string,
debug: __DEV__,
anonymousId: METAMETRICS_ANONYMOUS_ID,
// allow custom flush interval and event limit for dev and testing
// each is optional and can be set in the .js.env file
// if not set, the default values from the Segment SDK will be used
flushInterval: process.env.SEGMENT_FLUSH_INTERVAL as unknown as number,
flushAt: process.env.SEGMENT_FLUSH_EVENT_LIMIT as unknown as number,
};

if (__DEV__)
Logger.log(
`MetaMetrics client configured with: ${JSON.stringify(
config,
null,
2,
)}`,
);

this.instance = new MetaMetrics(createClient(config));
}
return this.instance;
Expand Down

0 comments on commit 330f415

Please sign in to comment.