@aller/blink
Version:
A library for tracking user behaviour.
68 lines • 3.82 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllVideoWatchEventsPrepared = exports.prepareSingleVideoWatchEvent = void 0;
var general_data_1 = __importDefault(require("../utils/general-data"));
var video_event_time_1 = require("../utils/video-event-time");
var player_sticky_1 = require("../utils/player-sticky");
function prepareSingleVideoWatchEvent(videoId, generalData, watchEvent, streamingMode, channelId) {
var startEvent = watchEvent.startEvent, stopEvent = watchEvent.stopEvent, watchTime = watchEvent.watchTime;
return __assign(__assign({}, generalData), { type: 'videoWatch', id: videoId, videoId: videoId, videoPlayVolume: startEvent.volume, videoStopVolume: stopEvent.volume, videoPlayPosition: startEvent.position, videoStopPosition: stopEvent.position, videoPlayReason: startEvent.reason, videoStopReason: stopEvent.reason, videoPlayMuted: startEvent.muted, videoStopMuted: stopEvent.muted, activeTime: watchTime, videoSticky: stopEvent.sticky, streamingMode: streamingMode,
channelId: channelId });
}
exports.prepareSingleVideoWatchEvent = prepareSingleVideoWatchEvent;
function prepareVideoWatchEvents(input) {
var startEvents = video_event_time_1.calculateVideoEventTime(input.page.state.video.events, input.videoId, input.page.state.player, input.playerId, input.time || new Date());
var general = general_data_1.default(input.page.state);
var watchEvents = startEvents.length > 0 ? startEvents : [];
var modifiedWithStickyInfo = player_sticky_1.modifyEventArrayWithStickyInfo(input.playerId, input.page.state.player, watchEvents);
return modifiedWithStickyInfo.map(function (watchEvent) {
return prepareSingleVideoWatchEvent(input.videoId, general, watchEvent, input.streamingMode, input.channelId);
});
}
exports.default = prepareVideoWatchEvents;
function getAllVideoWatchEventsPrepared(page, time) {
// Get all unique (videoId, playerId)-pairs from page
var allIdPairs = page.state.video.events.map(function (_a) {
var videoId = _a.videoId, playerId = _a.playerId, streamingMode = _a.streamingMode, channelId = _a.channelId;
return ({
videoId: videoId,
playerId: playerId,
streamingMode: streamingMode,
channelId: channelId,
});
});
var uniqueIdPairsObj = allIdPairs.reduce(function (register, idPair) {
register[idPair.videoId + idPair.playerId] = idPair;
return register;
}, {});
var uniqueIdPairs = Object.keys(uniqueIdPairsObj).map(function (key) { return uniqueIdPairsObj[key]; });
// Prepare all events for each (videoId, playerId)-pair, and merge them into a single list
return uniqueIdPairs.reduce(function (all, _a) {
var videoId = _a.videoId, playerId = _a.playerId, streamingMode = _a.streamingMode, channelId = _a.channelId;
var events = prepareVideoWatchEvents({
page: page,
time: time,
videoId: videoId,
playerId: playerId,
streamingMode: streamingMode,
channelId: channelId,
});
return all.concat(events);
}, []);
}
exports.getAllVideoWatchEventsPrepared = getAllVideoWatchEventsPrepared;
//# sourceMappingURL=prepare-video-watch-event.js.map