|
@@ -31,18 +31,28 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
|
get trackUrl() {
|
|
|
return this._endPoint + '/tracking/log/save';
|
|
|
}
|
|
|
+ get trackBeaconUrl() {
|
|
|
+ return this._endPoint + '/tracking/log/saveBeacon';
|
|
|
+ }
|
|
|
|
|
|
get trackPageViewUrl() {
|
|
|
return this._endPoint + '/tracking/log/save';
|
|
|
}
|
|
|
+ private cleanUnUsedKeys(trackObj) {
|
|
|
+ if (trackObj?.event) delete trackObj.event;
|
|
|
+ if (trackObj?.maxWaitTime) delete trackObj.maxWaitTime;
|
|
|
+ if (trackObj?.num) delete trackObj.num;
|
|
|
+ }
|
|
|
|
|
|
private toTrackEntity(params: TrackEntityType): TrackEntityType {
|
|
|
+ this.cleanUnUsedKeys(params.requestData);
|
|
|
const entity = {
|
|
|
appId: this._appId,
|
|
|
module: params.module,
|
|
|
type: params.type,
|
|
|
url: params.url || this._history.playload.url,
|
|
|
event: params.event,
|
|
|
+ num: this._config.num,
|
|
|
referrer: params.referrer || this._history.currentRef,
|
|
|
requestData: params.requestData,
|
|
|
};
|
|
@@ -100,8 +110,9 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
|
if (!this._stopTrack) {
|
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
|
const trackObj = cloneDeep(trackActionOption);
|
|
|
- delete trackObj.event;
|
|
|
- delete trackObj.maxWaitTime;
|
|
|
+ // delete trackObj.event;
|
|
|
+ // delete trackObj.maxWaitTime;
|
|
|
+ this.cleanUnUsedKeys(trackObj);
|
|
|
|
|
|
const payload: TrackEntityType = {
|
|
|
module: trackActionName,
|
|
@@ -112,13 +123,18 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
|
networkType: trackActionOption.networkType,
|
|
|
userId: this._config.user,
|
|
|
};
|
|
|
+ const plainObject = {
|
|
|
+ type: trackActionName,
|
|
|
+ payload: this.toTrackEntity(payload),
|
|
|
+ };
|
|
|
// this.toTrackEntity(payload);
|
|
|
+ const sendData = JSON.stringify(plainObject);
|
|
|
if ('sendBeacon' in navigator) {
|
|
|
- const blob = new Blob([JSON.stringify(payload)], {
|
|
|
- type: 'application/json; charset=UTF-8',
|
|
|
+ const blob = new Blob([sendData], {
|
|
|
+ type: 'text/plain',
|
|
|
});
|
|
|
-
|
|
|
- const isSend = navigator.sendBeacon(this.trackUrl, blob);
|
|
|
+ SDK._trackBeaconPayload = sendData;
|
|
|
+ const isSend = navigator.sendBeacon(this.trackBeaconUrl, blob);
|
|
|
return Promise.resolve(isSend);
|
|
|
}
|
|
|
return Promise.resolve(false);
|
|
@@ -129,8 +145,9 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
|
if (!this._stopTrack) {
|
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
|
const trackObj = cloneDeep(trackActionOption);
|
|
|
- delete trackObj.event;
|
|
|
- delete trackObj.maxWaitTime;
|
|
|
+ // delete trackObj.event;
|
|
|
+ // delete trackObj.maxWaitTime;
|
|
|
+ this.cleanUnUsedKeys(trackObj);
|
|
|
|
|
|
const payload: TrackEntityType = {
|
|
|
module: trackActionName,
|
|
@@ -151,9 +168,9 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
|
if (!this._stopTrack) {
|
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
|
const trackObj = cloneDeep(trackActionOption);
|
|
|
- delete trackObj.event;
|
|
|
- delete trackObj.maxWaitTime;
|
|
|
-
|
|
|
+ // delete trackObj.event;
|
|
|
+ // delete trackObj.maxWaitTime;
|
|
|
+ this.cleanUnUsedKeys(trackObj);
|
|
|
const payload: TrackEntityType = {
|
|
|
module: trackActionName,
|
|
|
type: 'start_track',
|
|
@@ -177,9 +194,9 @@ export class BaseTrack implements IBaseAction, ICustomAction {
|
|
|
if (!this._stopTrack) {
|
|
|
const historyPlayload = cloneDeep(this._history.playload);
|
|
|
const trackObj = cloneDeep(trackActionOption);
|
|
|
- delete trackObj.event;
|
|
|
- delete trackObj.maxWaitTime;
|
|
|
-
|
|
|
+ // delete trackObj.event;
|
|
|
+ // delete trackObj.maxWaitTime;
|
|
|
+ this.cleanUnUsedKeys(trackObj);
|
|
|
const payload: TrackEntityType = {
|
|
|
module: trackActionName,
|
|
|
type: 'end_track',
|