From b3186987415f240a19aec450da295f06d5f08ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Wed, 4 Jul 2018 12:37:38 +0200 Subject: [PATCH] Use more properties instead of context --- src/analytics/segment.js | 44 ++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/analytics/segment.js b/src/analytics/segment.js index 26e6a305..bf0d7938 100644 --- a/src/analytics/segment.js +++ b/src/analytics/segment.js @@ -16,12 +16,15 @@ if (!process.env.STORYBOOK_ENV) { const sessionId = uuid() -const getContext = store => { +const getContext = _store => ({ + ip: '0.0.0.0', +}) + +const extraProperties = store => { const state = store.getState() const { language, region } = langAndRegionSelector(state) const systemLocale = getSystemLocale() return { - ip: '0.0.0.0', appVersion: __APP_VERSION__, language, region, @@ -45,13 +48,9 @@ export const start = (store: *) => { return } load() - analytics.identify( - id, - {}, - { - context: getContext(store), - }, - ) + analytics.identify(id, extraProperties(store), { + context: getContext(store), + }) } export const stop = () => { @@ -75,9 +74,16 @@ export const track = (event: string, properties: ?Object) => { logger.error('analytics is not available') return } - analytics.track(event, properties, { - context: getContext(storeInstance), - }) + analytics.track( + event, + { + ...extraProperties(storeInstance), + ...properties, + }, + { + context: getContext(storeInstance), + }, + ) } export const page = (category: string, name: ?string, properties: ?Object) => { @@ -90,7 +96,15 @@ export const page = (category: string, name: ?string, properties: ?Object) => { logger.error('analytics is not available') return } - analytics.page(category, name, properties, { - context: getContext(storeInstance), - }) + analytics.page( + category, + name, + { + ...extraProperties(storeInstance), + ...properties, + }, + { + context: getContext(storeInstance), + }, + ) }