-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add app client id uuid for mixpanel client id
- Loading branch information
Showing
7 changed files
with
58 additions
and
2 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
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
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
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,43 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import logger from '../logger'; | ||
|
||
import store from './store'; | ||
|
||
// export type EventReportingState = Record<string, string | object | boolean>; | ||
const EVENT_REPORTING_KEY = 'eventReporting'; | ||
const CLIENT_ID_KEY = 'clientId'; | ||
|
||
export type EventReportingState = { | ||
[CLIENT_ID_KEY]?: string; | ||
}; | ||
|
||
/** | ||
* Called on app launch. | ||
* Initializes internal data structures for readiness. | ||
*/ | ||
const initialize = () => { | ||
logger.info('Intializing store settings key'); | ||
let eventReporting = store.get(EVENT_REPORTING_KEY); | ||
if (!eventReporting || typeof eventReporting !== 'object') { | ||
// create the default settings if no settings are saved yet | ||
logger.info( | ||
'No eventReporting state found. Creating a new instance and with a new clientId.', | ||
); | ||
eventReporting = { | ||
[CLIENT_ID_KEY]: uuidv4(), | ||
}; | ||
store.set(EVENT_REPORTING_KEY, eventReporting); | ||
} else if (eventReporting?.[CLIENT_ID_KEY] === undefined) { | ||
eventReporting = { | ||
...eventReporting, | ||
[CLIENT_ID_KEY]: uuidv4(), | ||
}; | ||
store.set(EVENT_REPORTING_KEY, eventReporting); | ||
} | ||
}; | ||
initialize(); | ||
|
||
export const getAppClientId = (): boolean => { | ||
return store.get(`${EVENT_REPORTING_KEY}.${CLIENT_ID_KEY}`); | ||
}; |
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
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
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