npaw-plugin-nwf
Version:
NPAW's Plugin
547 lines (546 loc) • 26.5 kB
TypeScript
import Session from '../sessions/Session';
import Experiment from './experiments/Experiment';
/**
* NpawProductAnalytics class is the base of npaw productAnalytics.
* Every plugin will have an instance.
*/
export default class ProductAnalytics {
private static VIDEOKEY_DEFAULT_IDENTIFIER;
private initialized;
private session;
private settings;
private page;
private config;
private searchQuery;
private url;
private contentHighlighted;
private contentHighlightTimeout;
private pendingVideoEvents;
private adapters;
private getReferral;
private setAnalyticsOptions;
private addVideoRequestListener;
private removeVideoRequestListener;
private videoListenerAccessor;
experiments: Experiment;
/**
* Constructs the NpawProductAnalytics class
*/
constructor(session: Session, getReferral: () => string, setAnalyticsOptions: (options: any) => void, addVideoRequestListener: (listener: any) => void, removeVideoRequestListener: (listener: any) => void);
/**
* Initializes product analytics
* @param {Object} productAnalyticsSettings product analytics settings
* @param {Object} [npawtmConfigValue] configuration settings
*/
initialize(productAnalyticsSettings: any): void;
/**
* Identify current page
* @private
*/
private identify;
/**
* Destroy
*/
destroy(): void;
/**
* Get anonymous user options
* @returns
*/
private getAuthenticatedUserOptions;
/**
* Get anonymous user options
* @returns
*/
private getAnonymousUserOptions;
/**
* Get options
* @returns
*/
private getOptions;
/**
* Get current user id
* @returns
*/
private getUserId;
/**
* Get current profile id
* @returns
*/
private getProfileId;
/**
* Get device UUID
* @returns
*/
private getDeviceUUID;
/**
* Fetch experiment variants
* @param userId User ID
* @param profileId Profile ID
* @param deviceId Device ID
* @private
*/
private fetchExperimentVariants;
/**
* Track adapter start
* @private
*/
private adapterTrackStart;
/**
* Execute after adapter is set to plugin
* @param {object} adapter Video adapter
* @param {string} [videoKey] Custom video identifier
*/
registerAdapter(adapter: any, videoKey?: string): void;
/**
* Execute before removing adapter from plugin
* @param {string} [videoKey] Custom video identifier
*/
removeAdapter(videoKey?: string): void;
/**
* Get adapter bound to video key
* @param videoKey
* @returns
*/
private getAdapter;
/**
* Get video key
* @param videoKey
* @returns
*/
private getVideoKey;
/**
* Video listener
* @param serviceName
* @param videoKey
* @param params
*/
private videoListener;
/**
* New user session
*/
newSession(): void;
/**
* Ends user session
*/
endSession(): void;
/**
* Checks if the session is active
* @returns
*/
sessionActive(): boolean;
/**
* Successful login
* @param {string} userId The unique identifier of the user
* @param {string} [profileId] The unique identifier of the profile
* @param {string} [profileType] The profile type
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
loginSuccessful(userId: string | number, profileId: string, profileType: string, dimensions: object, metrics: object): void;
/**
* Login unsuccessful
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
loginUnsuccessful(dimensions?: object, metrics?: object): void;
/**
* Logout
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
logout(dimensions?: object, metrics?: object): void;
/**
* User profile created
* @param {string} profileId The unique identifier of the profile
* @param {string} [profileType] The profile type
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
userProfileCreated(profileId: string, profileType?: string, dimensions?: object, metrics?: object): void;
/**
* User profile selected
* @param {string} profileId The unique identifier of the profile
* @param {string} [profileType] The profile type
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
userProfileSelected(profileId: string, profileType?: string, dimensions?: object, metrics?: object): void;
/**
* Fire user profile selected event
* @param {string} profileId The unique identifier of the profile
* @param {string} [profileType] The profile type
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
* @private
*/
_userProfileSelectedEvent(profileId: string, profileType?: string, dimensions?: object, metrics?: object): void;
/**
* User profile deleted
* @param {string} profileId The unique identifier of the profile
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
userProfileDeleted(profileId: string, dimensions?: object, metrics?: object): void;
/**
* Get user profile dimensions
* @param {string} profileId
* @param {string} profileType
* @param {boolean} ignoreSession
* @returns
* @private
*/
_getUserProfileDimensions(profileId: string, profileType?: string | null, ignoreSession?: boolean): {
profileId: string;
paIsBounce: boolean;
paIgnoreSession: boolean;
};
/**
* Tracks navigation by route
* @param {string} pageName The unique name to identify a page of the application.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackNavByRoute(route: string, dimensions: object, metrics: object): void;
/**
* Tracks navigation
* @param {string} pageName The unique name to identify a page of the application.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackNavByName(pageName: string, dimensions?: object, metrics?: object): void;
/**
* Automatically tracks navigation when page is cached by browser
* @param {Object} event
* @private
*/
private trackNavigationCached;
/**
* Tracks navigation (either manually or automatically)
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
* @private
*/
private trackNavigationInternal;
/**
* Tracks attribution
* @param {string} utmSource The UTM Source parameter. It is commonly used to identify a search engine, newsletter, or other source (i.e., Google, Facebook, etc.).
* @param {string} utmMedium The UTM Medium parameter. It is commonly used to identify a medium such as email or cost-per-click (cpc).
* @param {string} utmCampaign The UTM Campaign parameter. It is commonly used for campaign analysis to identify a specific product promotion or strategic campaign (i.e., spring sale).
* @param {string} utmTerm The UTM Term parameter. It is commonly used with paid search to supply the keywords for ads (i.e., Customer, NonBuyer, etc.).
* @param {string} utmContent The UTM Content parameter. It is commonly used for A/B testing and content-targeted ads to differentiate ads or links that point to the same URL (i.e., Banner1, Banner2, etc.)
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackAttribution(utmSource: string, utmMedium?: string, utmCampaign?: string, utmTerm?: string, utmContent?: string, dimensions?: object, metrics?: object): void;
/**
* Tracks attribution (either manually or automatically)
* @param {URLSearchParams} params Object where to look for UTM params.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
* @private
*/
private trackAttributionInternal;
/**
* Retrieves UTM params from querystring (utm_source, utm_medium, utm_campaign, utm_term, utm_content) and returns an object containing them but
* with key formatted as specified by utmFormatDot.
* @param {URLSearchParams} params Object where to look for UTM params
* @returns {{}}
* @private
*/
_getUTMParams(params: URLSearchParams): object | null;
/**
* Section goes into viewport.
* @param {string} section The section title. It is commonly used to indicate the section title presented over a grid layout (e.g. Recommended Movies, Continue Watching, etc).
* @param {Number} sectionOrder The section order within the page.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackSectionVisible(section: string, sectionOrder: number, dimensions?: object, metrics?: object): void;
/**
* Section goes out of viewport.
* @param {string} section The section title. It is commonly used to indicate the section title presented over a grid layout (e.g. Recommended Movies, Continue Watching, etc).
* @param {Number} sectionOrder The section order within the page.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackSectionHidden(section: string, sectionOrder: number, dimensions?: object, metrics?: object): void;
/**
* Sends a content highlight event if content is focused during, at least, highlightContentAfter ms.
* @param {string} section The section title. It is commonly used to indicate the section title presented over a grid layout (e.g. Recommended Movies, Continue Watching, etc).
* @param {number} sectionOrder The section order within the page.
* @param {string} column Used to indicate the column number where content is placed in a grid layout The first column is number 0.
* @param {string} row Used to indicate the row number where content is placed in a grid layout. The first row is number 0. In the case of a horizontal list instead of a grid, the row parameter should be set to 0.
* @param {string} contentLink The unique content identifier of the content linked.
* @param {string} contentLinkType The type of content link (i.e., contentId, movieGroupTitle, movieGroupId, seriesTitle, seriesId, seriesSeasonTitle, seriesSeasonId).
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
contentFocusIn(section: string, sectionOrder: number, column: number, row: number, contentLink: string, contentLinkType?: string, dimensions?: object, metrics?: object): void;
/**
* Content loses focus
* @private
*/
contentFocusOut(): void;
/**
* Sends a content highlight event using selected content info
* @private
*/
_trackContentHiglight(): void;
/**
* Tracks the location of user clicks.
* @param {string} section The section title. It is commonly used to indicate the section title presented over a grid layout (e.g. Recommended Movies, Continue Watching, etc).
* @param {number} sectionOrder The section order within the page.
* @param {number} column Used to indicate the column number where content is placed in a grid layout The first column is number 0.
* @param {number} row Used to indicate the row number where content is placed in a grid layout. The first row is number 0. In the case of a horizontal list instead of a grid, the row parameter should be set to 0.
* @param {string} contentLink The unique content identifier of the content linked.
* @param {string} [contentLinkType] The type of content link (i.e., contentId, movieGroupTitle, movieGroupId, seriesTitle, seriesId, seriesSeasonTitle, seriesSeasonId).
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackContentClick(section: string, sectionOrder: number, column: number, row: number, contentLink: string, contentLinkType?: string, dimensions?: object, metrics?: object): void;
/**
* Tracks when a VOD content starts playing be it automatically or through a user interaction.
* @param {string} contentId The unique content identifier of the content being played.
* @param {string} [movieGroupTitle] The movie group title.
* @param {string} [movieGroupId] The movie group identifier.
* @param {string} [seriesSeasonTitle] The series season title.
* @param {string} [seriesSeasonId] The series season identifier.
* @param {string} [seriesTitle] The series title.
* @param {string} [seriesId] The series identifier.
* @param {object} [dimensions] Dimensions to track
* @param {object} [metrics] Metrics to track
* @param {string} [videoKey] Custom video identifier.
*/
trackPlayVOD(contentId: string, movieGroupTitle?: string, movieGroupId?: string, seriesSeasonTitle?: string, seriesSeasonId?: string, seriesTitle?: string, seriesId?: string, dimensions?: object, metrics?: object, videoKey?: string): void;
/**
* Tracks when an EPG content starts playing be it automatically or through a user interaction.
* @param {string | null} channelId The channel identifier.
* @param {string | null} epgId The EPG identifier.
* @param {object} [dimensions] Dimensions to track
* @param {object} [metrics] Metrics to track
* @param {string} [videoKey] Custom video identifier.
*/
trackPlayEPG(channelId: string | null, epgId: string | null, dimensions?: object, metrics?: object, videoKey?: string): void;
/**
* Track play items
* @param {object[]} contentLinks An array of content links to track.
* @param {object} [dimensions] Dimensions to track.
* @param {object} [metrics] Metrics to track.
* @param {string} [videoKey] Custom video identifier.
*/
private trackPlayItems;
/**
* Tracks when a content starts playing be it automatically or through a user interaction.
* @param {string} contentLink The content identifier of the content being played.
* @param {string} [contentLinkType] The type of content link (i.e., contentId, movieGroupTitle, movieGroupId, seriesTitle, seriesId, seriesSeasonTitle, seriesSeasonId).
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
* @param {string} [videoKey] Custom video identifier
*/
trackPlay(contentLink: string, contentLinkType?: string, dimensions?: object, metrics?: object, videoKey?: string): void;
/**
* Tracks content watching events.
* @param {string} eventName The name of the interaction (i.e., Pause, Seek, Skip Intro, Skip Ads, Switch Language, etc.).
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
* @param {string} [videoKey] Custom video identifier
* @param {boolean} [startEvent] Internal param informing that current interaction is responsible of first player start
*/
trackPlayerInteraction(eventName: string, dimensions?: object, metrics?: object, videoKey?: string): void;
/**
* Handle player event (queueing event in case video has not started yet or flushing the event
* queue in case video starts)
*/
private handlePlayerEvent;
/**
* Track player event
*
* @param eventName The name of the interaction (i.e., Pause, Seek, Skip Intro, Skip Ads, Switch Language, etc.).
* @param contentLink The content identifier of the content being played.
* @param contentLinkType The type of content link (i.e., contentId, movieGroupTitle, movieGroupId, seriesTitle, seriesId, seriesSeasonTitle, seriesSeasonId).
* @param dimensions Dimensions to track
* @param metrics Metrics to track
* @param videoKey Video adapter identifier
*/
private trackPlayerEvent;
/**
* Tracks search query events.
* @param {string} searchQuery The search term entered by the user.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackSearchQuery(searchQuery: string, dimensions?: object, metrics?: object): void;
/**
* Tracks search result events.
* @param {integer} resultCount The number of search results returned by a search query.
* @param {String} [searchQuery] The search term entered by the user.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackSearchResult(resultCount: number, searchQuery?: string, dimensions?: object, metrics?: object): void;
/**
* Tracks user interactions with search results.
* @param {string} section The section title. It is commonly used to indicate the section title presented over a grid layout (e.g. Recommended Movies, Continue Watching, etc).
* @param {number} sectionOrder The section order within the page.
* @param {number} column The content placement column. It is commonly used to indicate the column number where content is placed in a grid layout (i.e.1, 2, etc..).
* @param {number} row The content placement row. It is commonly used to indicate the row number where content is placed in a grid layout (i.e.1, 2, etc..).
* @param {string} contentLink The content identifier. It is used for internal content unequivocally identification (i.e., AAA000111222).
* @param {string} [contentLinkType] The type of content link (i.e., contentId, movieGroupTitle, movieGroupId, seriesTitle, seriesId, seriesSeasonTitle, seriesSeasonId).
* @param {String} [searchQuery] The search term entered by the user.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackSearchClick(section: string | null, sectionOrder: number | null, column: number, row: number, contentLink: string, contentLinkType?: string, searchQuery?: string, dimensions?: object, metrics?: object): void;
/**
* Tracks the location of user clicks on EPG content.
* @param {string} channelId The channel identifier.
* @param {string} epgId The EPG item ID.
* @param {string} epgMode The EPG play mode (past / live / future)
* @param {string} contentLink The unique content identifier of the content linked.
* @param {string} [contentLinkType] The type of content link (i.e., contentId, movieGroupTitle, movieGroupId, seriesTitle, seriesId, seriesSeasonTitle, seriesSeasonId).
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackEPGClick(channelId: string | null, epgId: string | null, epgMode: string | null, contentId: string | null, contentLink: string, contentLinkType: string, dimensions?: object, metrics?: object): void;
/**
* Tracks external app start events.
* @param {string} appName The name of the application being used to deliver the content to the end-user (i.e., Netflix).
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackExternalAppLaunch(appName: string, dimensions?: object, metrics?: object): void;
/**
* Tracks external app stop events.
* @param {string} appName The name of the application being used to deliver the content to the end-user (i.e., Netflix).
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackExternalAppExit(appName: string, dimensions?: object, metrics?: object): void;
/**
* Tracks engagement events.
* @param {string} eventName The name of the engagement event (i.e., Share, Save, Rate, etc.).
* @param {string} [contentId] The unique content identifier of the content the user is engaging with.
* @param {string} [epgId] The EPG item ID.
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
*/
trackEngagementEvent(eventName: string, contentId?: string | null, epgId?: string | null, dimensions?: object, metrics?: object): void;
/**
* Track click event
* @param {string} controlName Name of the control receiving the click
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
* @param {boolean} [hasEndDatetime] For events with duration
*/
trackClick(controlName: string, dimensions?: object, metrics?: object, hasEndDatetime?: boolean): void;
/**
* Track custom event
* @param {string} eventName Name of the event to track
* @param {Object} [dimensions] Dimensions to track
* @param {Object} [metrics] Metrics to track
* @param {boolean} [hasEndDatetime] For events with duration
*/
trackEvent(eventName: string, dimensions?: object, metrics?: object, hasEndDatetime?: boolean): void;
/**
* Fires an event
* @param {string} eventName Name of the event to be fired
* @param {ProductAnalyticsEventType} eventType Type of the event being tracked
* @param {Object} dimensionsInternal Dimensions supplied by user
* @param {Object} dimensionsUser Specific event dimensions
* @param {Object} metrics Metrics to track
* @param {boolean} hasEndDatetime For events with duration
* @private
*/
private fireEventInternal;
/**
* Fires an adapter event (in case it is available)
* @param {string} eventName Event name
* @param {Object} dimensionsInternal Dimensions supplied by user
* @param {Object} dimensionsUser Specific event dimensions
* @param {Object} metrics Metrics to track
* @param {string} [videoKey] Custom video identifier
* @private
*/
private fireEventAdapter;
/**
* Builds a list of top level and custom dimensions
* @param {ProductAnalyticsEventType} eventType Type of the event being tracked
* @param {Object} dimensionsInternal Object containing list of internal dimensions
* @param {Object} dimensionsUser Object containing list of custom dimensions
* @private
*/
private buildDimensions;
/**
* Build section placement dimensions
* @param paIsBounce The bounce flag.
* @param paIgnoreSession The ignore session flag.
* @param section The section title. It is commonly used to indicate the section title presented over a grid layout (e.g. Recommended Movies, Continue Watching, etc).
* @param sectionOrder The section order within the page.
* @param column The content placement column. It is commonly used to indicate the column number where content is placed in a grid layout (i.e.1, 2, etc..).
* @param row The content placement row. It is commonly used to indicate the row number where content is placed in a grid layout (i.e.1, 2, etc..).
* @param contentLink The content identifier. It is used for internal content unequivocally identification (i.e., AAA000111222).
* @param contentLinkType The type of content link (i.e., contentId, movieGroupTitle, movieGroupId, seriesTitle, seriesId, seriesSeasonTitle, seriesSeasonId).
* @returns The section placement dimensions.
*/
private static buildSectionPlacementDimensions;
/**
* Build content link dimensions
* @param contentLink The content identifier of the content being played.
* @param contentLinkType The type of content link (i.e., contentId, movieGroupTitle, movieGroupId, seriesTitle, seriesId, seriesSeasonTitle, seriesSeasonId).
* @returns The content link dimensions.
*/
private static buildContentLinkDimensions;
/**
* Check state before sending an event
* @param {String} message Message to show in case validation fails
* @private
*/
private checkState;
/**
* Check coordinates
* @param {string} section The section title. It is commonly used to indicate the section title presented over a grid layout (e.g. Recommended Movies, Continue Watching, etc).
* @param {number} sectionOrder The section order within the page.
* @param {number} column The content placement column. It is commonly used to indicate the column number where content is placed in a grid layout (i.e.1, 2, etc..).
* @param {number} row The content placement row. It is commonly used to indicate the row number where content is placed in a grid layout (i.e.1, 2, etc..).
* @param {string} contentLink The content identifier. It is used for internal content unequivocally identification (i.e., AAA000111222).
* @param {string} message Message to show in case validation fails
* @param message
*/
private checkSectionCoordinates;
/**
* Check coordinate
* @param coordinate
* @returns True if the coordinate is valid, false otherwise.
*/
private static checkCoordinate;
/**
* Check content link
* @param contentLink
* @returns True if the content link is valid, false otherwise.
*/
private static checkContentLink;
/**
* Check content link type
* @param contentLinkType
* @returns True if the content link type is valid, false otherwise.
*/
private static checkContentLinkType;
/**
* Check content ID
* @param contentId The content identifier. It is used for internal content unequivocally identification (i.e., AAA000111222).
* @returns True if the content ID is valid, false otherwise.
*/
private static checkContentId;
/**
* Check EPG ID
* @param epgId The content identifier. It is used for internal content unequivocally identification (i.e., AAA000111222).
* @returns True if the EPG ID is valid, false otherwise.
*/
private static checkEpgId;
private onRequestQueued;
private onRequestWillSend;
/**
* Request sent handler
*/
private onRequestSent;
}