@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
JavaScript
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 = {
[ ]: valueType,
[ ]: title,
[ ]: id,
[ ]:
(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 {
[ ]: id,
[ ]: component_type,
[ ]:
cell_style || ANALYTICS_CORE_EVENTS.ITEM_NOT_AVAILABLE,
[ ]:
(source && encodeURIComponent(source)) || null,
[ ]: headerTitle,
};
}
function eventForMenuItemEntry({ item, index, isHome }) {
const { title, type, id } = item;
const itemReadableIndex = index + 1;
return {
[ ]:
(itemReadableIndex && itemReadableIndex.toString()) || null,
[ ]: type,
[ ]: title,
[ ]: id,
[ ]: isHome ? "YES" : "NO",
};
}