|
@@ -1,12 +1,13 @@
|
|
|
-import { IBaseAction } from '@medici/types';
|
|
|
+import { IBaseAction, ICustomAction, TrackActionOption } from '@medici/types';
|
|
|
import type { SDKInitConfig, PlatformType, SDKConfigType } from './sdk';
|
|
|
import type { IHistory } from './history';
|
|
|
import { collect } from './collector';
|
|
|
-export class BaseTrack implements IBaseAction {
|
|
|
+export class BaseTrack implements IBaseAction, ICustomAction {
|
|
|
protected _platform: PlatformType;
|
|
|
protected _config: SDKInitConfig;
|
|
|
protected _history: IHistory;
|
|
|
protected _endPoint: string;
|
|
|
+ protected _trackEndPoint: string;
|
|
|
protected _appId: string;
|
|
|
|
|
|
constructor(params: SDKConfigType) {
|
|
@@ -14,6 +15,7 @@ export class BaseTrack implements IBaseAction {
|
|
|
this._platform = params.platform;
|
|
|
this._appId = params.appId;
|
|
|
this._endPoint = params.endPoint;
|
|
|
+ this._trackEndPoint = params.trackEndPoint;
|
|
|
}
|
|
|
public trackView(url: string, referrer: string, uuid: string): void {
|
|
|
console.log('BaseTrack-trackView', url, referrer, uuid);
|
|
@@ -24,23 +26,50 @@ export class BaseTrack implements IBaseAction {
|
|
|
collect(this._endPoint, 'pageview', payload);
|
|
|
}
|
|
|
|
|
|
- public trackEvent(value: string, type: string, url?: string, uuid?: string): void {
|
|
|
- console.log('BaseTrack-TrackEvent', value, type, url, uuid);
|
|
|
+ public trackEvent(event_name: string, event_data: string, url?: string, uuid?: string): Promise<XMLHttpRequestResponseType> {
|
|
|
+ console.log('BaseTrack-TrackEvent', event_name, event_data, url, uuid);
|
|
|
const payload = Object.assign(this._history.playload, {
|
|
|
referrer: this._history.currentRef,
|
|
|
- event_type: 'custom',
|
|
|
- event_value: value,
|
|
|
+ event_name: event_name,
|
|
|
+ event_data: event_data,
|
|
|
});
|
|
|
- collect(this._endPoint, 'event', payload);
|
|
|
+ return collect(this._endPoint, 'event', payload);
|
|
|
}
|
|
|
|
|
|
public sendEvent(value: string, type: string, url?: string, uuid?: string): void {
|
|
|
console.log('BaseTrack-sendEvent', value, type, url, uuid);
|
|
|
const payload = Object.assign(this._history.playload, {
|
|
|
referrer: this._history.currentRef,
|
|
|
- event_type: type,
|
|
|
- event_value: value,
|
|
|
+ event_name: type,
|
|
|
+ event_data: value,
|
|
|
});
|
|
|
collect(this._endPoint, 'event', payload);
|
|
|
}
|
|
|
+
|
|
|
+ public track(trackActionName: string, trackActionOption?: TrackActionOption): void {
|
|
|
+ const payload = Object.assign(this._history.playload, {
|
|
|
+ referrer: this._history.currentRef,
|
|
|
+ ...trackActionOption,
|
|
|
+ trackActionName,
|
|
|
+ });
|
|
|
+ collect(this._trackEndPoint, 'track', payload);
|
|
|
+ }
|
|
|
+
|
|
|
+ public startTrack(trackActionName: string, trackActionOption?: TrackActionOption): void {
|
|
|
+ const payload = Object.assign(this._history.playload, {
|
|
|
+ referrer: this._history.currentRef,
|
|
|
+ ...trackActionOption,
|
|
|
+ trackActionName,
|
|
|
+ });
|
|
|
+ collect(this._trackEndPoint, 'startTrack', payload);
|
|
|
+ }
|
|
|
+
|
|
|
+ public endTrack(trackActionName: string, trackActionOption?: TrackActionOption): void {
|
|
|
+ const payload = Object.assign(this._history.playload, {
|
|
|
+ referrer: this._history.currentRef,
|
|
|
+ ...trackActionOption,
|
|
|
+ trackActionName,
|
|
|
+ });
|
|
|
+ collect(this._trackEndPoint, 'endTrack', payload);
|
|
|
+ }
|
|
|
}
|