|
@@ -1,4 +1,4 @@
|
|
-import { IBaseAction, ICustomAction, TrackActionOption } from '@medici/types';
|
|
|
|
|
|
+import { IBaseAction, ICustomAction, TrackActionOption, TrackEntityType } from '@medici/types';
|
|
import type { SDKInitConfig, PlatformType, SDKConfigType } from './sdk';
|
|
import type { SDKInitConfig, PlatformType, SDKConfigType } from './sdk';
|
|
import type { IHistory } from './history';
|
|
import type { IHistory } from './history';
|
|
import { collect } from './collector';
|
|
import { collect } from './collector';
|
|
@@ -12,7 +12,6 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
protected _config: SDKInitConfig;
|
|
protected _config: SDKInitConfig;
|
|
protected _history: IHistory;
|
|
protected _history: IHistory;
|
|
protected _endPoint: string;
|
|
protected _endPoint: string;
|
|
- protected _trackEndPoint: string;
|
|
|
|
protected _appId: string;
|
|
protected _appId: string;
|
|
private _timeOut: ReturnType<typeof setTimeout>;
|
|
private _timeOut: ReturnType<typeof setTimeout>;
|
|
|
|
|
|
@@ -21,24 +20,59 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
this._platform = params.platform;
|
|
this._platform = params.platform;
|
|
this._appId = params.appId;
|
|
this._appId = params.appId;
|
|
this._endPoint = params.endPoint;
|
|
this._endPoint = params.endPoint;
|
|
- this._trackEndPoint = params.trackEndPoint;
|
|
|
|
}
|
|
}
|
|
get _stopTrack() {
|
|
get _stopTrack() {
|
|
return SDK._stopTrack;
|
|
return SDK._stopTrack;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ get trackUrl() {
|
|
|
|
+ return this._endPoint + '/tracking/log/save';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ get trackPageViewUrl() {
|
|
|
|
+ return this._endPoint + '/tracking/log/save';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private toTrackEntity(params: TrackEntityType): TrackEntityType {
|
|
|
|
+ const entity = {
|
|
|
|
+ appId: this._appId,
|
|
|
|
+ module: params.module,
|
|
|
|
+ url: params.url || this._history.playload.url,
|
|
|
|
+ eventType: params.eventType,
|
|
|
|
+ referrer: params.referrer || this._history.currentRef,
|
|
|
|
+ requestData: params.requestData,
|
|
|
|
+ };
|
|
|
|
+ if (params.language) {
|
|
|
|
+ entity['language'] = params.language;
|
|
|
|
+ }
|
|
|
|
+ if (params.networkType) {
|
|
|
|
+ entity['networkType'] = params.networkType;
|
|
|
|
+ }
|
|
|
|
+ if (params.userId) {
|
|
|
|
+ entity['userId'] = params.userId;
|
|
|
|
+ }
|
|
|
|
+ return entity;
|
|
|
|
+ }
|
|
|
|
+
|
|
public trackView(url: string, referrer: string, uuid: string): Promise<XMLHttpRequestResponseType> {
|
|
public trackView(url: string, referrer: string, uuid: string): Promise<XMLHttpRequestResponseType> {
|
|
console.log('BaseTrack-trackView', url, referrer, uuid);
|
|
console.log('BaseTrack-trackView', url, referrer, uuid);
|
|
if (!this._stopTrack) {
|
|
if (!this._stopTrack) {
|
|
this._history.playload.url = url;
|
|
this._history.playload.url = url;
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
- const payload = Object.assign(historyPlayload, {
|
|
|
|
- ...this._config,
|
|
|
|
- referrer: this._history.currentRef,
|
|
|
|
|
|
+ // const payload = Object.assign(historyPlayload, {
|
|
|
|
+ // ...this._config,
|
|
|
|
+ // referrer: this._history.currentRef,
|
|
|
|
+ // url: url,
|
|
|
|
+ // });
|
|
|
|
+ const payload: TrackEntityType = {
|
|
|
|
+ module: 'pageview',
|
|
url: url,
|
|
url: url,
|
|
- });
|
|
|
|
|
|
+ eventType: 'pageview',
|
|
|
|
+ language: historyPlayload.language,
|
|
|
|
+ userId: this._config.user,
|
|
|
|
+ };
|
|
console.log('send-playload', payload);
|
|
console.log('send-playload', payload);
|
|
- return collect(this._endPoint, 'pageview', payload);
|
|
|
|
|
|
+ return collect(this.trackPageViewUrl, 'pageview', this.toTrackEntity(payload));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -47,61 +81,67 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
console.log('BaseTrack-TrackEvent', event_name, event_data, url, uuid);
|
|
console.log('BaseTrack-TrackEvent', event_name, event_data, url, uuid);
|
|
this._history.playload.url = url;
|
|
this._history.playload.url = url;
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
- const payload = Object.assign(historyPlayload, {
|
|
|
|
- referrer: this._history.currentRef,
|
|
|
|
- event_name: event_name,
|
|
|
|
- url: url,
|
|
|
|
- event_data: event_data,
|
|
|
|
- ...this._config,
|
|
|
|
- });
|
|
|
|
- console.log('send-playload', payload);
|
|
|
|
- return collect(this._endPoint, 'event', payload);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ // const payload = Object.assign(historyPlayload, {
|
|
|
|
+ // referrer: this._history.currentRef,
|
|
|
|
+ // event_name: event_name,
|
|
|
|
+ // url: url,
|
|
|
|
+ // event_data: event_data,
|
|
|
|
+ // ...this._config,
|
|
|
|
+ // });
|
|
|
|
|
|
- public sendEvent(value: string, type: string, url?: string, uuid?: string): Promise<XMLHttpRequestResponseType> {
|
|
|
|
- if (!this._stopTrack) {
|
|
|
|
- console.log('BaseTrack-sendEvent', value, type, url, uuid);
|
|
|
|
- const payload = Object.assign(this._history.playload, {
|
|
|
|
- referrer: this._history.currentRef,
|
|
|
|
|
|
+ const payload: TrackEntityType = {
|
|
|
|
+ module: event_name,
|
|
url: url,
|
|
url: url,
|
|
- event_name: type,
|
|
|
|
- event_data: value,
|
|
|
|
- ...this._config,
|
|
|
|
- });
|
|
|
|
- return collect(this._endPoint, 'event', payload);
|
|
|
|
|
|
+ eventType: event_data,
|
|
|
|
+ language: historyPlayload.language,
|
|
|
|
+ userId: this._config.user,
|
|
|
|
+ };
|
|
|
|
+ console.log('send-playload', payload);
|
|
|
|
+ return collect(this.trackPageViewUrl, 'event', this.toTrackEntity(payload));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public track(trackActionName: string, trackActionOption?: TrackActionOption): Promise<XMLHttpRequestResponseType> {
|
|
public track(trackActionName: string, trackActionOption?: TrackActionOption): Promise<XMLHttpRequestResponseType> {
|
|
if (!this._stopTrack) {
|
|
if (!this._stopTrack) {
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
- const payload = Object.assign(historyPlayload, {
|
|
|
|
- referrer: this._history.currentRef,
|
|
|
|
- ...trackActionOption,
|
|
|
|
- trackActionName,
|
|
|
|
- ...this._config,
|
|
|
|
- });
|
|
|
|
- return collect(this._trackEndPoint, 'track', payload);
|
|
|
|
|
|
+ const trackObj = cloneDeep(trackActionOption);
|
|
|
|
+ delete trackObj.eventType;
|
|
|
|
+ delete trackObj.maxWaitTime;
|
|
|
|
+
|
|
|
|
+ const payload: TrackEntityType = {
|
|
|
|
+ module: trackActionName,
|
|
|
|
+ eventType: trackActionOption.eventType,
|
|
|
|
+ requestData: Object.assign({ screen: historyPlayload.screen }, trackObj, this._config),
|
|
|
|
+ language: historyPlayload.language,
|
|
|
|
+ networkType: trackActionOption.networkType,
|
|
|
|
+ userId: this._config.user,
|
|
|
|
+ };
|
|
|
|
+ // this.toTrackEntity(payload);
|
|
|
|
+ return collect(this.trackUrl, 'track', this.toTrackEntity(payload));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public startTrack(trackActionName: string, trackActionOption?: TrackActionOption): Promise<XMLHttpRequestResponseType> {
|
|
public startTrack(trackActionName: string, trackActionOption?: TrackActionOption): Promise<XMLHttpRequestResponseType> {
|
|
if (!this._stopTrack) {
|
|
if (!this._stopTrack) {
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
- const payload = Object.assign(historyPlayload, {
|
|
|
|
- referrer: this._history.currentRef,
|
|
|
|
- ...trackActionOption,
|
|
|
|
- trackActionName,
|
|
|
|
- ...this._config,
|
|
|
|
- });
|
|
|
|
|
|
+ const trackObj = cloneDeep(trackActionOption);
|
|
|
|
+ delete trackObj.eventType;
|
|
|
|
+ delete trackObj.maxWaitTime;
|
|
|
|
|
|
|
|
+ const payload: TrackEntityType = {
|
|
|
|
+ module: trackActionName,
|
|
|
|
+ eventType: trackActionOption.eventType,
|
|
|
|
+ requestData: Object.assign({}, trackObj, this._config),
|
|
|
|
+ language: historyPlayload.language,
|
|
|
|
+ networkType: trackActionOption.networkType,
|
|
|
|
+ userId: this._config.user,
|
|
|
|
+ };
|
|
if (trackActionOption.maxWaitTime) {
|
|
if (trackActionOption.maxWaitTime) {
|
|
this._timeOut = setTimeout(() => {
|
|
this._timeOut = setTimeout(() => {
|
|
this.endTrack(trackActionName, trackActionOption);
|
|
this.endTrack(trackActionName, trackActionOption);
|
|
}, trackActionOption.maxWaitTime);
|
|
}, trackActionOption.maxWaitTime);
|
|
}
|
|
}
|
|
- return collect(this._trackEndPoint, 'startTrack', payload);
|
|
|
|
|
|
+ return collect(this.trackUrl, 'startTrack', this.toTrackEntity(payload));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -109,13 +149,19 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
clearTimeout(this._timeOut);
|
|
clearTimeout(this._timeOut);
|
|
if (!this._stopTrack) {
|
|
if (!this._stopTrack) {
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
- const payload = Object.assign(historyPlayload, {
|
|
|
|
- referrer: this._history.currentRef,
|
|
|
|
- ...trackActionOption,
|
|
|
|
- trackActionName,
|
|
|
|
- ...this._config,
|
|
|
|
- });
|
|
|
|
- return collect(this._trackEndPoint, 'endTrack', payload);
|
|
|
|
|
|
+ const trackObj = cloneDeep(trackActionOption);
|
|
|
|
+ delete trackObj.eventType;
|
|
|
|
+ delete trackObj.maxWaitTime;
|
|
|
|
+
|
|
|
|
+ const payload: TrackEntityType = {
|
|
|
|
+ module: trackActionName,
|
|
|
|
+ eventType: trackActionOption.eventType,
|
|
|
|
+ requestData: Object.assign({}, trackObj, this._config),
|
|
|
|
+ language: historyPlayload.language,
|
|
|
|
+ networkType: trackActionOption.networkType,
|
|
|
|
+ userId: this._config.user,
|
|
|
|
+ };
|
|
|
|
+ return collect(this.trackUrl, 'endTrack', this.toTrackEntity(payload));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|