Browse Source

Use more properties instead of context

master
Gaëtan Renaudeau 7 years ago
parent
commit
b318698741
  1. 44
      src/analytics/segment.js

44
src/analytics/segment.js

@ -16,12 +16,15 @@ if (!process.env.STORYBOOK_ENV) {
const sessionId = uuid() const sessionId = uuid()
const getContext = store => { const getContext = _store => ({
ip: '0.0.0.0',
})
const extraProperties = store => {
const state = store.getState() const state = store.getState()
const { language, region } = langAndRegionSelector(state) const { language, region } = langAndRegionSelector(state)
const systemLocale = getSystemLocale() const systemLocale = getSystemLocale()
return { return {
ip: '0.0.0.0',
appVersion: __APP_VERSION__, appVersion: __APP_VERSION__,
language, language,
region, region,
@ -45,13 +48,9 @@ export const start = (store: *) => {
return return
} }
load() load()
analytics.identify( analytics.identify(id, extraProperties(store), {
id, context: getContext(store),
{}, })
{
context: getContext(store),
},
)
} }
export const stop = () => { export const stop = () => {
@ -75,9 +74,16 @@ export const track = (event: string, properties: ?Object) => {
logger.error('analytics is not available') logger.error('analytics is not available')
return return
} }
analytics.track(event, properties, { analytics.track(
context: getContext(storeInstance), event,
}) {
...extraProperties(storeInstance),
...properties,
},
{
context: getContext(storeInstance),
},
)
} }
export const page = (category: string, name: ?string, properties: ?Object) => { 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') logger.error('analytics is not available')
return return
} }
analytics.page(category, name, properties, { analytics.page(
context: getContext(storeInstance), category,
}) name,
{
...extraProperties(storeInstance),
...properties,
},
{
context: getContext(storeInstance),
},
)
} }

Loading…
Cancel
Save