Skip to content

Commit

Permalink
feat: android auto analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
KestasVenslauskas committed Jun 20, 2024
1 parent 049b5d6 commit 8dee8fe
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 30 deletions.
12 changes: 12 additions & 0 deletions PlaybackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import {
onPodcastsTabOpened,
onRecommendedTabOpened,
} from './app/car/AndroidAuto';
import {debounce} from 'lodash';
import analytics from '@react-native-firebase/analytics';

const sendAnalyticsEvent = debounce((eventName: string) => {
Gemius.sendPageViewedEvent(eventName);
analytics().logEvent(eventName);
}, 500);

const PlaybackService = async () => {
TrackPlayer.addEventListener(Event.RemotePause, () => {
Expand Down Expand Up @@ -139,18 +146,23 @@ function setupAndroidAuto() {
onRecommendedTabOpened();
case event.mediaId === TAB_RECOMMENDED:
onRecommendedTabOpened();
sendAnalyticsEvent('android_auto_recommended_open');
break;
case event.mediaId === TAB_LIVE:
onLiveTabOpened();
sendAnalyticsEvent('android_auto_live_open');
break;
case event.mediaId === TAB_NEWEST:
onNewestTabOpened();
sendAnalyticsEvent('android_auto_newest_open');
break;
case event.mediaId === TAB_PODCASTS:
onPodcastsTabOpened();
sendAnalyticsEvent('android_auto_podcasts_open');
break;
case event.mediaId.startsWith('podcast-'):
onPodcastSelect(event.mediaId);
sendAnalyticsEvent(`android_auto_podcast_open_${event.mediaId.split('-')[1]}`);
break;
default:
console.warn('Unhandled browse event', event);
Expand Down
42 changes: 36 additions & 6 deletions app/car/AndroidAuto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import {fetchStreamData} from '../components/videoComponent/fetchStreamData';
import {CarPlayPodcastItem, isMediaArticle} from '../api/Types';
import {CategoryListItem, PlayListItem} from './types';
import {IMG_SIZE_XS, buildArticleImageUri, buildImageUri} from '../util/ImageUtil';
import {
SQUARE_LRT_KLASIKA,
SQUARE_LRT_LITHUANICA,
SQUARE_LRT_OPUS,
SQUARE_LRT_PLUS,
SQUARE_LRT_RADIJAS,
SQUARE_LRT_TV,
} from '../constants';

const TAB_DEBOUNCE_TIME = 30 * 1000;

Expand Down Expand Up @@ -143,8 +151,7 @@ export const onLiveTabOpened = withDebounce(
[TAB_LIVE]: data.map((item) => ({
title: item.channelTitle ?? item.title,
url: item.streamUri,
//TODO: add local poster
artwork: item.poster,
artwork: getImageByChannelId(item.poster),
isLiveStream: true,
pitchAlgorithm: PitchAlgorithm.Voice,
type: TrackType.HLS,
Expand All @@ -157,7 +164,7 @@ export const onLiveTabOpened = withDebounce(
mediaId: String(i),
title: item.channelTitle ?? item.title,
playable: '0',
iconUri: item.poster,
iconUri: getImageByChannelId(item.poster),
mediaUri: item.streamUri,
groupTitle: TAB_LIVE,
})),
Expand Down Expand Up @@ -215,9 +222,9 @@ export const onPodcastsTabOpened = withDebounce(

const items = await fetchCarPodcasts(1000).then((data) => {
if (data.items.length) {
data.items.forEach((item) => {
item.title = item.title.replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, '');
});
// data.items.forEach((item) => {
// item.title = item.title.replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, '');
// });
data.items.sort((a, b) => a.title.localeCompare(b.title));
return data.items;
}
Expand Down Expand Up @@ -327,3 +334,26 @@ export const onPodcastSelect = withDebounce(
'podcast',
2000,
);

const getImageByChannelId = (channelId?: string) => {
switch (channelId) {
case '1': {
return SQUARE_LRT_TV;
}
case '2': {
return SQUARE_LRT_PLUS;
}
case '3': {
return SQUARE_LRT_LITHUANICA;
}
case '5': {
return SQUARE_LRT_KLASIKA;
}
case '6': {
return SQUARE_LRT_OPUS;
}
default: {
return SQUARE_LRT_RADIJAS;
}
}
};
1 change: 0 additions & 1 deletion app/car/BaseListTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class BaseListTemplate {
items?.map((item) => ({
text: item.text,
detailText: item.detailText,
image: item.image,
imgUrl: item.imgUrl as any,
})) ?? [],
},
Expand Down
23 changes: 15 additions & 8 deletions app/car/live/LiveTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import {fetchCarLivePlaylist} from '../../api';
import {PlayListItem} from '../types';
import {BaseListTemplate} from '../BaseListTemplate';
import {fetchStreamData} from '../../components/videoComponent/fetchStreamData';
import {
SQUARE_LRT_KLASIKA,
SQUARE_LRT_LITHUANICA,
SQUARE_LRT_OPUS,
SQUARE_LRT_PLUS,
SQUARE_LRT_RADIJAS,
SQUARE_LRT_TV,
} from '../../constants';

export const TEMPLATE_ID_LIVE = 'lrt-list-template-live';

Expand Down Expand Up @@ -34,8 +42,7 @@ class LiveTemplate extends BaseListTemplate {
id: stream.mediaId,
text: stream.channelTitle ?? stream.title,
// detailText: stream.title,
image: getImageByChannelId(stream.poster),
imgUrl: undefined,
imgUrl: getImageByChannelId(stream.poster),
streamUrl: stream.streamUri,
}));
return items;
Expand All @@ -49,22 +56,22 @@ class LiveTemplate extends BaseListTemplate {
const getImageByChannelId = (channelId?: string) => {
switch (channelId) {
case '1': {
return require('./assets/ic_tv.png');
return SQUARE_LRT_TV;
}
case '2': {
return require('./assets/ic_plius.png');
return SQUARE_LRT_PLUS;
}
case '3': {
return require('./assets/ic_lituanica.png');
return SQUARE_LRT_LITHUANICA;
}
case '5': {
return require('./assets/ic_klasika.png');
return SQUARE_LRT_KLASIKA;
}
case '6': {
return require('./assets/ic_opus.png');
return SQUARE_LRT_OPUS;
}
default: {
return require('./assets/ic_radijas.png');
return SQUARE_LRT_RADIJAS;
}
}
};
Expand Down
3 changes: 0 additions & 3 deletions app/car/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {ImageSourcePropType} from 'react-native';

export type CarCategory = 'live' | 'newest';

export type CategoryListItem = {
Expand All @@ -13,7 +11,6 @@ export type PlayListItem = {
id: string | number;
text: string;
detailText?: string;
image?: ImageSourcePropType;
imgUrl?: string;
streamUrl: string;
isLiveStream?: boolean;
Expand Down
8 changes: 8 additions & 0 deletions app/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ export const LRT_LITHUANICA = 'https://www.lrt.lt/media/logo/WORLD.jpg?v=2024512
export const LRT_RADIJAS = 'https://www.lrt.lt/media/logo/LR.jpg?v=2024152153';
export const LRT_KLASIKA = 'https://www.lrt.lt/media/logo/Klasika.jpg?v=2024152156';
export const LRT_OPUS = 'https://www.lrt.lt/media/logo/Opus.jpg?v=2024152157';

//Square stream covers
export const SQUARE_LRT_TV = 'https://www.lrt.lt/images/app_logo/TV.png';
export const SQUARE_LRT_PLUS = 'https://www.lrt.lt/images/app_logo/LTV2.png';
export const SQUARE_LRT_LITHUANICA = 'https://www.lrt.lt/images/app_logo/WORLD.png';
export const SQUARE_LRT_RADIJAS = 'https://www.lrt.lt/images/app_logo/LR.png';
export const SQUARE_LRT_KLASIKA = 'https://www.lrt.lt/images/app_logo/Klasika.png';
export const SQUARE_LRT_OPUS = 'https://www.lrt.lt/images/app_logo/Opus.png';
16 changes: 8 additions & 8 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2120,19 +2120,19 @@ PODS:
- react-native-google-cast/RNGoogleCast (4.6.2):
- PromisesObjC
- React
- react-native-pager-view (6.3.1):
- react-native-pager-view (6.3.3):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-render-html (6.3.4):
- React-Core
- react-native-safe-area-context (4.10.4):
- react-native-safe-area-context (4.10.5):
- React-Core
- react-native-slider (4.5.2):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-theoplayer (7.4.0):
- react-native-theoplayer (7.5.1):
- google-cast-sdk-dynamic-xcframework (~> 4.8)
- React-Core
- THEOplayer-Integration-GoogleCast/Base (~> 7.4)
Expand Down Expand Up @@ -2357,7 +2357,7 @@ PODS:
- RCT-Folly (= 2022.05.16.00)
- React-Core
- ReactCommon/turbomodule/core
- RNScreens (3.31.1):
- RNScreens (3.32.0):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -2715,11 +2715,11 @@ SPEC CHECKSUMS:
react-native-carplay: c0327ae947e4a12c7d66315d54254fdf87a982ec
react-native-gemius-plugin: 003b164539125055787a816a7b65976b19bf4a27
react-native-google-cast: d7bdfd1a0eeba84afde03b9722351ec29543e74c
react-native-pager-view: 0bcba39275cec9d1a50535c3c8c29924c66b67e7
react-native-pager-view: ce73434826e4dca60108c3b3a30d83792ff28b0c
react-native-render-html: 984dfe2294163d04bf5fe25d7c9f122e60e05ebe
react-native-safe-area-context: 399a5859f6acbdf67f671c69b53113f535f3b5b0
react-native-safe-area-context: a240ad4b683349e48b1d51fed1611138d1bdad97
react-native-slider: 9cfd2f0af9efe89a3ed372fcda8eca65109aa94c
react-native-theoplayer: 534aa9b81b2e1ac91fcfbe72cc6b30323906d358
react-native-theoplayer: bf778000f7aa85534ead32bcc534d6d76b3e94d6
react-native-track-player: 82ef1756ffeea61140fea17519ecd6d64ec3cf3e
react-native-webview: af5750ca782633c6c730a015946fb921497b4e7b
React-nativeconfig: b42fe8e97a8d164aebeb6821a27076406b64fbb9
Expand Down Expand Up @@ -2754,7 +2754,7 @@ SPEC CHECKSUMS:
RNNotifee: 8e2d3df3f0e9ce8f5d1fe4c967431138190b6175
RNPermissions: 60d60ce58c13537514288f285910c8b1cd12908d
RNReanimated: 3c15d836bc232658f355d404b17e2a3f9046fe6c
RNScreens: f0e300a3be13eff48f8afb0b5c6fc558c9369b03
RNScreens: 136d868cc4a78b41042a1a5f1cb42b99a47033f5
RNShare: 0fad69ae2d71de9d1f7b9a43acf876886a6cb99c
RNSVG: a48668fd382115bc89761ce291a81c4ca5f2fd2e
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
"react-native-google-cast": "4.8.0",
"react-native-linear-gradient": "^2.8.3",
"react-native-modal": "^13.0.1",
"react-native-pager-view": "6.3.1",
"react-native-pager-view": "6.3.3",
"react-native-permissions": "^3.10.1",
"react-native-reanimated": "^3.5.4",
"react-native-render-html": "^6.3.4",
"react-native-safe-area-context": "^4.10.4",
"react-native-screens": "3.31.1",
"react-native-safe-area-context": "^4.10.5",
"react-native-screens": "3.32.0",
"react-native-share": "^10.2.1",
"react-native-svg": "^15.3.0",
"react-native-tab-view": "^3.5.2",
"react-native-theoplayer": "^7.4.0",
"react-native-theoplayer": "^7.5.1",
"react-native-track-player": "https://github.com/lovegaoshi/react-native-track-player#dev-android-auto",
"react-native-webview": "13.10.3",
"react-navigation-collapsible": "6.2.0",
Expand Down

0 comments on commit 8dee8fe

Please sign in to comment.