Skip to content

Commit b8f0ee9

Browse files
authored
Merge pull request #153 from BuildFire/feat/new-analytics-integration
feat(analytics): include common watch duration time
2 parents 6919a6c + 3142440 commit b8f0ee9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

control/content/controllers/content.home.controller.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@
304304
// map throw items to get items type
305305
let indexedFeedItems = hits.map(_item => {
306306
const proxyItem = result.data.items.find(_proxyItem => _proxyItem.guid === _item._source.data.id);
307+
if (!proxyItem) return null;
307308

309+
_item._source.data.title = proxyItem.title;
308310
let enclosureData = sharedUtils.checkEnclosuresTag(proxyItem, MEDIUM_TYPES);
309311
let mediaTagData = sharedUtils.checkMediaTag(proxyItem, MEDIUM_TYPES);
310312

@@ -318,6 +320,7 @@
318320
return _item;
319321
});
320322

323+
indexedFeedItems = indexedFeedItems.filter(_item => _item !== null);
321324
callback(null, indexedFeedItems);
322325
}).catch((err) => {
323326
callback(err);
@@ -749,13 +752,13 @@
749752
updateMasterItem(_defaultData);
750753
ContentHome.data = angular.copy(_defaultData);
751754
} else {
752-
if (!ContentHome.data.analyticsRegistered) {
755+
if (!ContentHome.data.isAnalyticsRegistered) {
753756
AnalyticsManager.init((err) => {
754757
if (err) console.error(err);
755758

756-
ContentHome.data.analyticsRegistered = true;
759+
ContentHome.data.isAnalyticsRegistered = true;
757760
ContentHome.data.default = false;
758-
saveDataWithDelay({...ContentHome.data, default: false, analyticsRegistered: true});
761+
saveDataWithDelay({...ContentHome.data, default: false, isAnalyticsRegistered: true});
759762
});
760763
} else if (ContentHome.data.content.feeds && ContentHome.data.content.feeds.length) {
761764
const feeds = angular.copy(ContentHome.data.content.feeds);

widget/app.services.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
imageUrl: item.imageSrcUrl,
174174
};
175175
const eventKey = `${item.guid}_secondsWatch`;
176+
const commonAnalyticsKey = (itemType === 'video') ? 'videoWatchDuration' : 'audioWatchDuration';
176177
if (state === 'play') {
177178
trackPlayedItem({ item, itemType });
178179
if (currentTime) {
@@ -184,6 +185,7 @@
184185
lastAnalyticsTime += 5;
185186
metaData._buildfire = { aggregationValue: 5 }; // 5 seconds
186187
AnalyticsManager.trackEvent(eventKey, metaData);
188+
AnalyticsManager.trackEvent(commonAnalyticsKey, metaData);
187189
}, 5 * 1000);
188190
}
189191
} else if (state === 'pause') {
@@ -196,6 +198,7 @@
196198
if (currentTime > 0 && extraTime > 0 && extraTime <= 5) {
197199
metaData._buildfire = { aggregationValue: extraTime };
198200
AnalyticsManager.trackEvent(eventKey, metaData);
201+
AnalyticsManager.trackEvent(commonAnalyticsKey, metaData);
199202
}
200203
}
201204
} else if (state === 'buffer' && currentTime) {

widget/global/AnalyticsManager.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,18 @@ class AnalyticsManager {
7272
key: 'audioPlaysCount',
7373
description: 'Track total audios plays count in the app, offering insights into overall engagement and popularity.',
7474
},
75+
{
76+
title: `Total Audio Watch Duration`,
77+
key: 'audioWatchDuration',
78+
description: 'Track audios total watch time in the app, offering insights into overall engagement and popularity.',
79+
},
80+
{
81+
title: `Total Video Watch Duration`,
82+
key: 'videoWatchDuration',
83+
description: 'Track videos total watch time in the app, offering insights into overall engagement and popularity.',
84+
},
7585
];
7686

77-
// bulkRegister is a new method will be added to the sdk
7887
buildfire.analytics.bulkRegisterEvents(registeringArray, { silentNotification: true }, callback);
7988
}
8089
}

0 commit comments

Comments
 (0)