UNPKG

@applicaster/zapp-react-native-ui-components

Version:

Applicaster Zapp React Native ui components for the Quick Brick App

96 lines (78 loc) 2.92 kB
import * as R from "ramda"; import { postAnalyticEvent } from "@applicaster/zapp-react-native-tvos-app/AnalyticsManager"; import { extensionsEvents } from "@applicaster/zapp-react-native-utils/analyticsUtils/AnalyticsEvents/helper"; import { ANALYTICS_CORE_EVENTS, ANALYTICS_ENTRY_EVENTS, ANALYTICS_COMPONENT_EVENTS, ANALYTICS_MENU_ITEM_EVENTS, } from "../"; export function sendTapCellEvent(item, component, headerTitle, itemIndex) { const itemReadableIndex = itemIndex + 1; const analyticsProperties = R.compose( R.reject(R.isNil), R.merge(eventForEntry(item, itemReadableIndex)) )(eventForComponent(component, headerTitle)); postEvent(ANALYTICS_CORE_EVENTS.TAP_CELL, analyticsProperties); } export function sendTapMenuItem({ item, index, isHome }) { const analyticsProperties = R.compose(R.reject(R.isNil))( eventForMenuItemEntry({ item, index, isHome }) ); postEvent(ANALYTICS_CORE_EVENTS.TAP_MENU_ICON, analyticsProperties); if (isHome) { postEvent(ANALYTICS_CORE_EVENTS.HOME_SCREEN_VIEWED, null); } } function postEvent(event, properties) { postAnalyticEvent(event, properties); } function eventForEntry(item, itemIndex) { const { title, type: { value: valueType }, id, } = item; const analyticsCustomProperties = extensionsEvents(item.extensions); const analyticsEvents = { [ANALYTICS_ENTRY_EVENTS.ITEM_TYPE]: valueType, [ANALYTICS_ENTRY_EVENTS.ITEM_TITLE]: title, [ANALYTICS_ENTRY_EVENTS.ITEM_ID]: id, [ANALYTICS_ENTRY_EVENTS.ITEM_INDEX]: (itemIndex && itemIndex.toString()) || null, }; if (analyticsCustomProperties) { analyticsEvents.analyticsCustomProperties = analyticsCustomProperties; } return analyticsEvents; } function eventForComponent( component, headerTitle, // Zapp Pipes data passed for group components zappPipesData = null ) { const { id, component_type, styles, data } = component; const { cell_style } = styles; const source = data?.source || zappPipesData?.data?.url || null; return { [ANALYTICS_COMPONENT_EVENTS.COMPONENT_ID]: id, [ANALYTICS_COMPONENT_EVENTS.COMPONENT_TYPE]: component_type, [ANALYTICS_COMPONENT_EVENTS.CELL_STYLE]: cell_style || ANALYTICS_CORE_EVENTS.ITEM_NOT_AVAILABLE, [ANALYTICS_COMPONENT_EVENTS.COMPONENT_SOURCE]: (source && encodeURIComponent(source)) || null, [ANALYTICS_COMPONENT_EVENTS.HEADER_TITLE]: headerTitle, }; } function eventForMenuItemEntry({ item, index, isHome }) { const { title, type, id } = item; const itemReadableIndex = index + 1; return { [ANALYTICS_MENU_ITEM_EVENTS.ITEM_INDEX]: (itemReadableIndex && itemReadableIndex.toString()) || null, [ANALYTICS_MENU_ITEM_EVENTS.ITEM_TYPE]: type, [ANALYTICS_MENU_ITEM_EVENTS.ITEM_TITLE]: title, [ANALYTICS_MENU_ITEM_EVENTS.ITEM_ID]: id, [ANALYTICS_MENU_ITEM_EVENTS.ITEM_HOME_SCREEN]: isHome ? "YES" : "NO", }; }