Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tiagogm/7b66f199f9b9910e158a19af5ec7399b to your computer and use it in GitHub Desktop.
Save tiagogm/7b66f199f9b9910e158a19af5ec7399b to your computer and use it in GitHub Desktop.
//configuration of all events from multiple root level pages
const eventsRegister = {
...SEARCH_EVENTS_CONFIG,
...LISTING_EVENTS_CONFIG
//loads more
}
// for example, in `src/views/search/events.ts` file
export const SEARCH_EVENTS_CONFIG: EventConfigMap = {
[SEARCH_EVENTS.datedSearch]: [evtCh.GA, evtCh.KSM, evtCh.FB],
[SEARCH_EVENTS.advancedFiltersClick]: [evtCh.GA, evtCh.KSM, evtCh.DblClick],
}
//configure each channel to it's particual service/module file
const eventProxy = {
//this is where each specific service handled third party integration
[evtCh.GA]: gaService.event,
[evtCh.KSM]: ksmService.event
}
const trackEvent = (event: IEvent, data: EventData) => {
(eventsRegister[event]||[]).forEach(channel => {
eventProxy[channel](event);
})
}
export const analyticsService = {
trackEvent,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment