540 lines
16 KiB
TypeScript
540 lines
16 KiB
TypeScript
// Metro module 13464 (f13465).
|
|
import ExperimentStore from "../experiments/ExperimentStore";
|
|
import ApexExperimentStore from "../experiments/apex/ApexExperimentStore";
|
|
import LabFeatureStore from "../labs/LabFeatureStore";
|
|
import AuthenticationStore from "../../stores/AuthenticationStore";
|
|
import ICYMIStore from "./ICYMIStore";
|
|
import { v4 } from "../../_bundle/Module514";
|
|
import { ICYMIAnalytics, DEFAULT_UX_VARIATION } from "./ICYMIAnalytics";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let c9343_7 = 300000;
|
|
let c9343_8 = null;
|
|
let c9343_9 = [];
|
|
let previousIcymiSessionCount = 0;
|
|
let c9343_11 = new Map();
|
|
class ICYMISession {
|
|
constructor(r7 = [], r3 = "list") {
|
|
const triggerType = r3;
|
|
this._sessionId = v4();
|
|
this._startTimestamp = Date.now();
|
|
this._endTimestamp = null;
|
|
this._activeItems = [];
|
|
this._dwellCount = 0;
|
|
this._impressionCount = 0;
|
|
this._dwelledItemIdMap = new Map();
|
|
this._impressionItemIdMap = new Map();
|
|
this._impressionItemTypes = new Set();
|
|
this._reloadCount = 0;
|
|
this._feedFetchCount = 0;
|
|
this._dwelledItemsChangedCount = 0;
|
|
this._interactionCount = 0;
|
|
this._actionCount = 0;
|
|
this._latestDwellStartTimeMs = 0;
|
|
this._timeout = setTimeout(() => this.endSession(), c9343_7);
|
|
ICYMIAnalytics.trackFeedSessionStarted({
|
|
icymiSessionId: this._sessionId,
|
|
sessionStartTimeMs: this._startTimestamp,
|
|
previousIcymiSessionCount,
|
|
uxVariation: DEFAULT_UX_VARIATION
|
|
});
|
|
if (r7.length > 0) {
|
|
this.startItemsDwell(r7.map((item) => ({
|
|
...item,
|
|
triggerType,
|
|
isInitiallyVisible: true
|
|
})));
|
|
}
|
|
}
|
|
get sessionId() {
|
|
return this._sessionId;
|
|
}
|
|
get startTimestamp() {
|
|
return this._startTimestamp;
|
|
}
|
|
get endTimestamp() {
|
|
return this._endTimestamp;
|
|
}
|
|
get dwellCount() {
|
|
return this._dwellCount;
|
|
}
|
|
get uniqueDwellCount() {
|
|
return this._dwelledItemIdMap.size;
|
|
}
|
|
get impressionCount() {
|
|
return this._impressionCount;
|
|
}
|
|
get uniqueImpressionCount() {
|
|
return this._impressionItemIdMap.size;
|
|
}
|
|
get interactionCount() {
|
|
return this._interactionCount;
|
|
}
|
|
get reloadCount() {
|
|
return this._reloadCount;
|
|
}
|
|
get feedFetchCount() {
|
|
return this._feedFetchCount;
|
|
}
|
|
get dwelledItemsChangedCount() {
|
|
return this._dwelledItemsChangedCount;
|
|
}
|
|
get impressionItemTypes() {
|
|
return this._impressionItemTypes;
|
|
}
|
|
getImpression(c20478_0) {
|
|
return this._activeItems.find((_activeItem) => _activeItem.itemId === c20478_0);
|
|
}
|
|
startItemsDwell(a0) {
|
|
this._resetTimeout();
|
|
c9343_9 = a0;
|
|
if (a0.length === this._activeItems.length && a0.every((item, index) => this._activeItems[index].itemId === item.itemId)) {
|
|
return this._activeItems;
|
|
}
|
|
this._dwelledItemsChangedCount = this._dwelledItemsChangedCount + 1;
|
|
const _activeItems = [];
|
|
const set = new Set(this._activeItems.map((_activeItem) => _activeItem.itemId));
|
|
for (const item of a0) {
|
|
const impression = this.getImpression(item.itemId);
|
|
if (impression != null) {
|
|
_activeItems.push(impression);
|
|
set.delete(item.itemId);
|
|
} else {
|
|
_activeItems.push(this._createImpression(item));
|
|
}
|
|
}
|
|
set.forEach((item) => this._endImpression(item));
|
|
this._activeItems = _activeItems;
|
|
return this._activeItems;
|
|
}
|
|
trackItemsLongImpression(a0) {
|
|
for (const item of a0) {
|
|
const impression = this.getImpression(item.itemId);
|
|
let r38 = impression;
|
|
if (r38 == null) {
|
|
r38 = this._constructImpressionFromInput(item);
|
|
}
|
|
const r40 = r38;
|
|
const _impressionCount = this._impressionCount + 1;
|
|
this._impressionCount = _impressionCount;
|
|
r38.sessionImpressionIndex = _impressionCount;
|
|
const _impressionItemIdMap = this._impressionItemIdMap;
|
|
const itemId = item.itemId;
|
|
let r47 = this._impressionItemIdMap.get(item.itemId);
|
|
if (r47 == null) {
|
|
r47 = 0;
|
|
}
|
|
_impressionItemIdMap.set(itemId, r47 + 1);
|
|
let itemOccurenceCountInSession = this._dwelledItemIdMap.get(r40.itemId);
|
|
if (itemOccurenceCountInSession == null) {
|
|
itemOccurenceCountInSession = 0;
|
|
}
|
|
let itemCardHeight = c9343_11.get(r40.itemId);
|
|
if (itemCardHeight == null) {
|
|
itemCardHeight = r40.itemCardHeight;
|
|
}
|
|
if (itemCardHeight == null) {
|
|
itemCardHeight = null;
|
|
}
|
|
let uxVariation = r40.uxVariation;
|
|
if (uxVariation == null) {
|
|
uxVariation = DEFAULT_UX_VARIATION;
|
|
}
|
|
ICYMIAnalytics.trackFeedItemDwell1s({
|
|
icymiSessionId: this._sessionId,
|
|
impressionId: r40.impressionId,
|
|
itemId: r40.itemId,
|
|
itemType: r40.itemType,
|
|
dwellStartTimeMs: r40.impressionStartTimestamp,
|
|
triggerType: r40.triggerType,
|
|
itemOccurenceCountInSession,
|
|
itemFeedIndex: r40.itemFeedIndex,
|
|
itemScore: r40.itemScore,
|
|
isInitiallyVisible: r40.isInitiallyVisible,
|
|
itemChannelType: r40.itemChannelType,
|
|
itemCardHeight,
|
|
isDwelling: impression != null,
|
|
interactionActionTypes: r40.interactionActionTypes,
|
|
interactionCount: r40.interactionCount,
|
|
uxVariation,
|
|
sessionImpressionIndex: r40.sessionImpressionIndex
|
|
});
|
|
}
|
|
}
|
|
trackItemInteraction(a0, a1, a2) {
|
|
const impression = this.getImpression(a0);
|
|
const impressionId = impression?.impressionId;
|
|
let uxVariation = impression?.uxVariation;
|
|
if (uxVariation == null) {
|
|
uxVariation = DEFAULT_UX_VARIATION;
|
|
}
|
|
const _interactionCount = this._interactionCount + 1;
|
|
this._interactionCount = _interactionCount;
|
|
ICYMIAnalytics.trackItemInteraction({
|
|
id: a0,
|
|
type: a1,
|
|
actionType: a2,
|
|
impressionId,
|
|
uxVariation,
|
|
sessionInteractionIndex: _interactionCount,
|
|
icymiSessionId: this._sessionId
|
|
});
|
|
if (impression != null) {
|
|
impression.interactionActionTypes.push(a2);
|
|
impression.interactionCount = impression.interactionCount + 1;
|
|
}
|
|
}
|
|
trackFeedItemActioned(a0) {
|
|
const impression = this.getImpression(a0.itemId);
|
|
let uxVariation = impression?.uxVariation;
|
|
if (uxVariation == null) {
|
|
uxVariation = DEFAULT_UX_VARIATION;
|
|
}
|
|
const _actionCount = this._actionCount + 1;
|
|
this._actionCount = _actionCount;
|
|
let impressionId = impression?.impressionId;
|
|
if (impressionId == null) {
|
|
impressionId = null;
|
|
}
|
|
ICYMIAnalytics.trackFeedItemActioned({
|
|
icymiSessionId: this._sessionId,
|
|
uxVariation,
|
|
sessionActionIndex: _actionCount,
|
|
itemId: a0.itemId,
|
|
itemType: a0.itemType,
|
|
impressionId,
|
|
actionParameters: a0.actionParameters
|
|
});
|
|
}
|
|
trackFeedFilterActioned(a0) {
|
|
const r7 = a0.itemId != null ? this.getImpression(a0.itemId) : null;
|
|
let uxVariation = r7?.uxVariation;
|
|
if (uxVariation == null) {
|
|
uxVariation = DEFAULT_UX_VARIATION;
|
|
}
|
|
const _actionCount = this._actionCount + 1;
|
|
this._actionCount = _actionCount;
|
|
let impressionId = r7?.impressionId;
|
|
if (impressionId == null) {
|
|
impressionId = null;
|
|
}
|
|
ICYMIAnalytics.trackFeedFilterActioned({
|
|
icymiSessionId: this._sessionId,
|
|
uxVariation,
|
|
sessionActionIndex: _actionCount,
|
|
filterParameters: a0.filterParameters,
|
|
itemId: a0.itemId,
|
|
itemType: a0.itemType,
|
|
impressionId
|
|
});
|
|
}
|
|
trackFeedPageActioned(a0) {
|
|
const _actionCount = this._actionCount + 1;
|
|
this._actionCount = _actionCount;
|
|
ICYMIAnalytics.trackFeedPageActioned({
|
|
icymiSessionId: this._sessionId,
|
|
uxVariation: DEFAULT_UX_VARIATION,
|
|
sessionActionIndex: _actionCount,
|
|
...a0
|
|
});
|
|
}
|
|
incrementReloadCount() {
|
|
this._resetTimeout();
|
|
this._reloadCount = this._reloadCount + 1;
|
|
}
|
|
incrementFeedFetchCount() {
|
|
this._feedFetchCount = this._feedFetchCount + 1;
|
|
}
|
|
endAllImpressions() {
|
|
[...this._activeItems].forEach((item) => this._endImpression(item.itemId));
|
|
}
|
|
endSession() {
|
|
this.endAllImpressions();
|
|
this._endTimestamp = Date.now();
|
|
ICYMIAnalytics.trackFeedSessionCompleted({
|
|
icymiSessionId: this._sessionId,
|
|
sessionDurationMs: this._endTimestamp - this._startTimestamp,
|
|
sessionStartTimeMs: this._startTimestamp,
|
|
sessionEndTimeMs: this._endTimestamp,
|
|
impressionCount: this._impressionCount,
|
|
uniqueImpressionCount: this._impressionItemIdMap.size,
|
|
impressionItemTypes: Array.from(this._impressionItemTypes),
|
|
feedReloadCount: this._reloadCount,
|
|
feedDwelledItemsChangedCount: this._dwelledItemsChangedCount,
|
|
feedFetchCount: this._feedFetchCount,
|
|
latestDwellStartTimeMs: this._latestDwellStartTimeMs,
|
|
previousIcyMiSessionCount: previousIcymiSessionCount,
|
|
interactionCount: this._interactionCount,
|
|
dwelledCount: this._dwellCount,
|
|
uniqueDwelledCount: this._dwelledItemIdMap.size,
|
|
uxVariation: DEFAULT_UX_VARIATION
|
|
});
|
|
clearTimeout(this._timeout);
|
|
previousIcymiSessionCount = previousIcymiSessionCount + 1;
|
|
c9343_8 = null;
|
|
c9343_11.clear();
|
|
return this;
|
|
}
|
|
_resetTimeout() {
|
|
clearTimeout(this._timeout);
|
|
this._timeout = setTimeout(() => this.endSession(), c9343_7);
|
|
}
|
|
_createImpression(a0) {
|
|
const r11 = this._constructImpressionFromInput(a0);
|
|
this._dwellCount = this._dwellCount + 1;
|
|
const _dwelledItemIdMap = this._dwelledItemIdMap;
|
|
const itemId = a0.itemId;
|
|
let r14 = this._dwelledItemIdMap.get(a0.itemId);
|
|
if (r14 == null) {
|
|
r14 = 0;
|
|
}
|
|
_dwelledItemIdMap.set(itemId, r14 + 1);
|
|
this._impressionItemTypes.add(a0.itemType);
|
|
this._latestDwellStartTimeMs = r11.impressionStartTimestamp;
|
|
return r11;
|
|
}
|
|
_constructImpressionFromInput(a0) {
|
|
const r11 = {
|
|
itemId: a0.itemId,
|
|
itemType: a0.itemType,
|
|
impressionId: v4(),
|
|
impressionStartTimestamp: Date.now(),
|
|
impressionComplete: false,
|
|
triggerType: a0.triggerType,
|
|
itemFeedIndex: a0.itemFeedIndex,
|
|
itemScore: a0.itemScore,
|
|
isInitiallyVisible: a0.isInitiallyVisible,
|
|
itemChannelType: a0.itemChannelType,
|
|
itemCardHeight: null,
|
|
uxVariation: null,
|
|
interactionActionTypes: null,
|
|
interactionCount: 0,
|
|
sessionImpressionIndex: null
|
|
};
|
|
let itemCardHeight = c9343_11.get(a0.itemId);
|
|
if (itemCardHeight == null) {
|
|
itemCardHeight = null;
|
|
}
|
|
r11.itemCardHeight = itemCardHeight;
|
|
r11.uxVariation = DEFAULT_UX_VARIATION;
|
|
r11.interactionActionTypes = [];
|
|
return r11;
|
|
}
|
|
_endImpression(c20482_0) {
|
|
const r7 = this._activeItems.findIndex((_activeItem) => _activeItem.itemId === c20482_0);
|
|
const r19 = this._activeItems[r7];
|
|
const r1 = r19 != null;
|
|
let r20 = null;
|
|
if (r1) {
|
|
r19.impressionEndTimestamp = Date.now();
|
|
r19.impressionComplete = true;
|
|
let itemOccurenceCountInSession = this._dwelledItemIdMap.get(r19.itemId);
|
|
if (itemOccurenceCountInSession == null) {
|
|
itemOccurenceCountInSession = 0;
|
|
}
|
|
let itemCardHeight = c9343_11.get(r19.itemId);
|
|
if (itemCardHeight == null) {
|
|
itemCardHeight = r19.itemCardHeight;
|
|
}
|
|
if (itemCardHeight == null) {
|
|
itemCardHeight = null;
|
|
}
|
|
let uxVariation = r19.uxVariation;
|
|
if (uxVariation == null) {
|
|
uxVariation = DEFAULT_UX_VARIATION;
|
|
}
|
|
ICYMIAnalytics.trackFeedItemDwelled({
|
|
icymiSessionId: this._sessionId,
|
|
impressionId: r19.impressionId,
|
|
dwellTimeMs: r19.impressionEndTimestamp - r19.impressionStartTimestamp,
|
|
itemId: r19.itemId,
|
|
itemType: r19.itemType,
|
|
dwellStartTimeMs: r19.impressionStartTimestamp,
|
|
dwellEndTimeMs: r19.impressionEndTimestamp,
|
|
triggerType: r19.triggerType,
|
|
itemOccurenceCountInSession,
|
|
itemFeedIndex: r19.itemFeedIndex,
|
|
itemScore: r19.itemScore,
|
|
isInitiallyVisible: r19.isInitiallyVisible,
|
|
itemChannelType: r19.itemChannelType,
|
|
itemCardHeight,
|
|
uxVariation,
|
|
interactionActionTypes: r19.interactionActionTypes,
|
|
interactionCount: r19.interactionCount,
|
|
sessionImpressionIndex: r19.sessionImpressionIndex
|
|
});
|
|
this._activeItems.splice(r7, 1);
|
|
r20 = r19;
|
|
}
|
|
return r20;
|
|
}
|
|
}
|
|
class ICYMISessionStore extends Module589.Store {
|
|
initialize() {
|
|
this.waitFor(ApexExperimentStore, AuthenticationStore, ICYMIStore, ExperimentStore, LabFeatureStore);
|
|
}
|
|
get currentSession() {
|
|
return c9343_8;
|
|
}
|
|
get endedSessionCount() {
|
|
return previousIcymiSessionCount;
|
|
}
|
|
}
|
|
const iCYMISessionStore = new ICYMISessionStore(Dispatcher, {
|
|
ICYMI_TAB_OPENED: function handleTabOpened() {
|
|
let r10 = c9343_8 != null;
|
|
if (r10) {
|
|
c9343_8.endSession();
|
|
r10 = true;
|
|
}
|
|
if (c9343_9.length > 0) {
|
|
c9343_8 = new ICYMISession(c9343_9, "focus");
|
|
r10 = true;
|
|
}
|
|
return r10;
|
|
},
|
|
ICYMI_TAB_CLOSED: function handleTabClosed() {
|
|
let r4 = c9343_8 != null;
|
|
if (r4) {
|
|
c9343_8.endSession();
|
|
r4 = true;
|
|
}
|
|
return r4;
|
|
},
|
|
ICYMI_SET_FOCUSED_TAB: function handleIcymiTabFocussed({ focused }) {
|
|
const r11 = c9343_8;
|
|
if (focused) {
|
|
if (r11 != null) {
|
|
if (c9343_9.length > 0) {
|
|
c9343_8.startItemsDwell(c9343_9.map((item) => ({
|
|
...item,
|
|
triggerType: "focus",
|
|
isInitiallyVisible: true
|
|
})));
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
let r15 = c9343_8 != null;
|
|
if (r15) {
|
|
c9343_8.endSession();
|
|
r15 = true;
|
|
}
|
|
if (c9343_9.length > 0) {
|
|
c9343_8 = new ICYMISession(c9343_9, "focus");
|
|
r15 = true;
|
|
}
|
|
return r15;
|
|
}
|
|
let r2 = r11 != null;
|
|
if (r2) {
|
|
c9343_8.endAllImpressions();
|
|
r2 = true;
|
|
}
|
|
return r2;
|
|
},
|
|
ICYMI_ITEMS_DWELL_START: function handleItemsDwellStart(a0) {
|
|
if (c9343_8 == null) {
|
|
c9343_8 = new ICYMISession(a0.items, "list");
|
|
} else {
|
|
c9343_8.startItemsDwell(a0.items);
|
|
}
|
|
return true;
|
|
},
|
|
ICYMI_ITEMS_LONG_IMPRESSION: function handleItemsLongImpression(a0) {
|
|
if (c9343_8 == null) {
|
|
c9343_8 = new ICYMISession(a0.items, "list");
|
|
}
|
|
c9343_8.trackItemsLongImpression(a0.items);
|
|
return true;
|
|
},
|
|
RELOAD_ICYMI: function handleReloadICYMI() {
|
|
let r4 = c9343_8 != null;
|
|
if (r4) {
|
|
c9343_8.incrementReloadCount();
|
|
r4 = true;
|
|
}
|
|
return r4;
|
|
},
|
|
LOAD_ICYMI_DEHYDRATED: function handleLoadICYMIDehydrated() {
|
|
let r0 = c9343_8 != null;
|
|
if (r0) {
|
|
c9343_8.incrementFeedFetchCount();
|
|
const r2 = c9343_8 != null;
|
|
r0 = true;
|
|
if (r2) {
|
|
c9343_8.endAllImpressions();
|
|
r0 = true;
|
|
}
|
|
}
|
|
return r0;
|
|
},
|
|
APP_STATE_UPDATE: function handleAppStateUpdate(a0) {
|
|
let r0 = a0.state !== "active" && c9343_8 != null;
|
|
if (r0) {
|
|
let r10 = c9343_8 != null;
|
|
if (r10) {
|
|
c9343_8.endSession();
|
|
r10 = true;
|
|
}
|
|
r0 = r10;
|
|
}
|
|
return r0;
|
|
},
|
|
CHANNEL_SELECT: function handleChannelSelected() {
|
|
let r1 = c9343_8 != null;
|
|
if (r1) {
|
|
let r6 = c9343_8 != null;
|
|
if (r6) {
|
|
c9343_8.endAllImpressions();
|
|
r6 = true;
|
|
}
|
|
r1 = r6;
|
|
}
|
|
return r1;
|
|
},
|
|
ICYMI_SET_CARD_HEIGHT: function handleSetCardHeight(a0) {
|
|
c9343_11.set(a0.itemId, a0.height);
|
|
return true;
|
|
},
|
|
ICYMI_ITEM_INTERACTED: function handleItemInteracted(a0) {
|
|
if (c9343_8 == null) {
|
|
c9343_8 = new ICYMISession(c9343_9, "focus");
|
|
}
|
|
c9343_8.trackItemInteraction(a0.itemId, a0.itemType, a0.actionType);
|
|
return true;
|
|
},
|
|
ICYMI_FEED_ITEM_ACTIONED: function handleFeedItemActioned(a0) {
|
|
if (c9343_8 == null) {
|
|
c9343_8 = new ICYMISession(c9343_9, "focus");
|
|
}
|
|
c9343_8.trackFeedItemActioned(a0);
|
|
return true;
|
|
},
|
|
ICYMI_FEED_FILTER_ACTIONED: function handleFeedFilterActioned(a0) {
|
|
if (c9343_8 == null) {
|
|
c9343_8 = new ICYMISession(c9343_9, "focus");
|
|
}
|
|
c9343_8.trackFeedFilterActioned(a0);
|
|
return true;
|
|
},
|
|
ICYMI_FEED_PAGE_ACTIONED: function handleFeedPageActioned(a0) {
|
|
if (c9343_8 == null) {
|
|
c9343_8 = new ICYMISession(c9343_9, "focus");
|
|
}
|
|
c9343_8.trackFeedPageActioned(a0);
|
|
return true;
|
|
}
|
|
});
|
|
export default iCYMISessionStore;
|
|
export function resetGlobalState() {
|
|
if (c9343_8 != null) {
|
|
clearTimeout(c9343_8._timeout);
|
|
}
|
|
c9343_8 = null;
|
|
c9343_9 = [];
|
|
previousIcymiSessionCount = 0;
|
|
c9343_11.clear();
|
|
}
|
|
export { ICYMISession };
|