unified-plugin
Version:
NPAW's Unified Plugin
168 lines (167 loc) • 5.2 kB
TypeScript
/**
* NpawAppAnalytics class is the base of npaw appanalytics.
* Every plugin will have an instance.
*/
export default class AppAnalytics {
private core;
private coreStorage;
private options;
private accountCode;
private analyticsRequestHandler?;
private requestBuilder;
_beat: any;
sessionExpire: number;
appAnalyticsStarted: boolean;
appAnalyticsStopped: boolean;
_lastNavigation: {
page: string;
route: string;
};
_registeredProperties: {
dimensions: object;
values: object;
} | null;
_firstActive: number | undefined;
/**
* Constructs the NpawAppAnalytics class
*/
constructor(accountCode: string);
/**
* Gets Analytics options. See {@link Options}.
*/
protected getOptions(): any;
/**
* This method will start appAnalytics logic, setting storage as needed.
* Will call fireSessionStart the first time and fireNav for every subsequent route change.
*
* @param dimensions - Object of key:value params to add to the request.
* @param forceNewSession - boolean to force open a new session.
*/
private begin;
/**
* Starts a new session. If a sessions exists stops it and starts a new one
*
* @param options - Object of key:value options (optional).
* @param dimensions - Object of key:value params to add to the request (optional).
*/
newSession(options?: object, dimensions?: object): void;
/**
* Stops the session
*
* @param params - Object of key:value params to add to the request.
*/
endSession(params?: object): void;
private _setLastActive;
protected getAccountCode(): string;
/**
* Emits session start request.
*
* @param dimensions - Object of key:value params to add to the request.
*/
fireSessionStart(dimensions?: object): void;
/**
* Emits session start request.
*
* @param params - Object of key:value params to add to
* the request.
*/
fireSessionStop(params?: object): void;
/**
* Emits session start request.
*
* @param dimensions - Object of key:value params to add to the request.
*/
fireNav(dimensions?: object): void;
/**
* Emits session start request.
*
* @param eventName - Event name.
* @param dimensions - Object of key:value dimensions to add to the request.
* @param values - Object of key:value values to add to the request.
* @param topLevelDimensions - Object of key:value topLevelDimensions to add to the request.
*/
fireEvent(eventName?: string, dimensions?: object, values?: object, topLevelDimensions?: object): void;
/** Register properties sent by the User, to send in all the events
*
* @param dimensions - Object of key:value dimensions.
* @param values - Object of key:value values.
*/
register(dimensions?: object, values?: object): void;
/** Calls register if registeredProperties is empty
*
* @param dimensions - Object of key:value dimensions.
* @param values - Object of key:value values.
*/
registerOnce(dimensions: object, values: object): void;
/** Unregister all properties registered with register() */
unregister(): void;
/**
* Splits params in dimensions (strings) and values (numbers)
*
* @param dimensions - Object of key:value dimensions to split before adding to request.
* @param values - Object of key:value values to split before adding to request.
* @param eventName - Event name.
* @param isNavigation - Boolean to check if it's a navigation event.
* @param isStart - Boolean to check if it's a start event.
*/
private _getParamsJson;
/**
*
* @param willSendEvent
* @param service
* @param params
* @private
*/
private _sendAppAnalytics;
private _processNavigation;
private _processSessionStart;
private _processSessionStop;
private _processCustomEvent;
/**
* Process Internal Params object
* @param params
* @returns {{}|*|{}}
* @private
*/
private _parseInternalParams;
/**
* Sends beat request
*
* @param diffTime - Time since the last ping
*
* @private
* @memberof NpawAppAnalytics.prototype
*/
private _sendBeat;
/**
* Check if change page/route (to avoid duplicated navigations)
* @param params
* @returns {boolean}
* @private
*/
private _checkDifferentNavigation;
/**
* Returns a json with the metrics to be reported in beats when changed
*
* @memberof NpawAppAnalytics.prototype
*/
getSessionMetrics(): object;
/**
* Is post method enabled
* @returns {boolean}
*/
isMethodPostEnabled(): boolean;
/**
*
* @param willSendLog
* @param service
* @param params
*/
private _sendPluginLogs;
private _logBeginEvent;
private _logFireSessionStartEvent;
private _logFireSessionStopEvent;
private _logFireEventListener;
private _logFireNavListener;
private _logFireNewSessionListener;
}