|
@@ -10,12 +10,14 @@ export interface playloadType {
|
|
screen: string;
|
|
screen: string;
|
|
language: string;
|
|
language: string;
|
|
url: string;
|
|
url: string;
|
|
|
|
+ ua: string;
|
|
|
|
+ referrer?: string;
|
|
}
|
|
}
|
|
export class IHistory {
|
|
export class IHistory {
|
|
protected _sdk: SDK;
|
|
protected _sdk: SDK;
|
|
protected _playload: playloadType;
|
|
protected _playload: playloadType;
|
|
- private currentRef: string;
|
|
|
|
- private currentUrl: string;
|
|
|
|
|
|
+ private _currentRef: string;
|
|
|
|
+ private _currentUrl: string;
|
|
|
|
|
|
constructor(sdk: SDK, appId?: string) {
|
|
constructor(sdk: SDK, appId?: string) {
|
|
this._sdk = sdk;
|
|
this._sdk = sdk;
|
|
@@ -27,6 +29,14 @@ export class IHistory {
|
|
return this._playload;
|
|
return this._playload;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ get currentUrl(): string {
|
|
|
|
+ return this._currentUrl;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ get currentRef(): string {
|
|
|
|
+ return this._currentRef;
|
|
|
|
+ }
|
|
|
|
+
|
|
init(): void {
|
|
init(): void {
|
|
console.log('history init');
|
|
console.log('history init');
|
|
global.document.addEventListener('readystatechange', this.handleReadystatechange.bind(this), true);
|
|
global.document.addEventListener('readystatechange', this.handleReadystatechange.bind(this), true);
|
|
@@ -34,7 +44,7 @@ export class IHistory {
|
|
global.history.replaceState = hook(global.history, 'replaceState', this.handlePushState.bind(this));
|
|
global.history.replaceState = hook(global.history, 'replaceState', this.handlePushState.bind(this));
|
|
const {
|
|
const {
|
|
screen: { width, height },
|
|
screen: { width, height },
|
|
- navigator: { language },
|
|
|
|
|
|
+ navigator: { language, userAgent },
|
|
location: { hostname, pathname, search },
|
|
location: { hostname, pathname, search },
|
|
// localStorage,
|
|
// localStorage,
|
|
// document,
|
|
// document,
|
|
@@ -42,14 +52,16 @@ export class IHistory {
|
|
} = global;
|
|
} = global;
|
|
|
|
|
|
const screen = `${width}x${height}`;
|
|
const screen = `${width}x${height}`;
|
|
- this.currentUrl = `${pathname}${search}`;
|
|
|
|
- this.currentRef = global.document.referrer;
|
|
|
|
|
|
+ this._currentUrl = `${pathname}${search}`;
|
|
|
|
+ this._currentRef = global.document.referrer;
|
|
this._playload = {
|
|
this._playload = {
|
|
website: '',
|
|
website: '',
|
|
hostname: hostname,
|
|
hostname: hostname,
|
|
screen: screen,
|
|
screen: screen,
|
|
language: language,
|
|
language: language,
|
|
- url: this.currentUrl,
|
|
|
|
|
|
+ url: this._currentUrl,
|
|
|
|
+ ua: userAgent,
|
|
|
|
+ referrer: this._currentRef,
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -57,23 +69,25 @@ export class IHistory {
|
|
if (global.document.readyState === 'complete') {
|
|
if (global.document.readyState === 'complete') {
|
|
console.log('handleReadystatechange');
|
|
console.log('handleReadystatechange');
|
|
this.observeDocument();
|
|
this.observeDocument();
|
|
|
|
+ this._sdk.eventer.initElementCssEvents(global.document.body);
|
|
|
|
+ this._sdk.trackView(this._currentUrl, this._currentRef, this._playload.website);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
handlePushState(data: any, unused: string, url?: string | URL): void {
|
|
handlePushState(data: any, unused: string, url?: string | URL): void {
|
|
try {
|
|
try {
|
|
if (!url) return;
|
|
if (!url) return;
|
|
- this.currentRef = this.currentUrl;
|
|
|
|
|
|
+ this._currentRef = this._currentUrl;
|
|
const newUrl = url.toString();
|
|
const newUrl = url.toString();
|
|
if (newUrl.substring(0, 4) === 'http') {
|
|
if (newUrl.substring(0, 4) === 'http') {
|
|
- this.currentUrl = '/' + newUrl.split('/').splice(3).join('/');
|
|
|
|
|
|
+ this._currentUrl = '/' + newUrl.split('/').splice(3).join('/');
|
|
} else {
|
|
} else {
|
|
- this.currentUrl = newUrl;
|
|
|
|
|
|
+ this._currentUrl = newUrl;
|
|
}
|
|
}
|
|
- console.log('diff', this.currentUrl !== this.currentRef);
|
|
|
|
- if (this.currentUrl !== this.currentRef) {
|
|
|
|
|
|
+ console.log('diff', this._currentUrl !== this._currentRef);
|
|
|
|
+ if (this._currentUrl !== this._currentRef) {
|
|
console.log('trackView', data, unused, url);
|
|
console.log('trackView', data, unused, url);
|
|
- this._sdk.trackView(this.currentUrl, this.currentRef, this._playload.website);
|
|
|
|
|
|
+ this._sdk.trackView(this._currentUrl, this._currentRef, this._playload.website);
|
|
// trackView();
|
|
// trackView();
|
|
}
|
|
}
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -86,13 +100,16 @@ export class IHistory {
|
|
observeDocument(): void {
|
|
observeDocument(): void {
|
|
const monitorMutate = (mutations: MutationRecord[]) => {
|
|
const monitorMutate = (mutations: MutationRecord[]) => {
|
|
console.log('mutations', mutations);
|
|
console.log('mutations', mutations);
|
|
|
|
+ const nodeGroup: Node[][] = [];
|
|
mutations.forEach((mutation: MutationRecord) => {
|
|
mutations.forEach((mutation: MutationRecord) => {
|
|
- const element: Node = mutation.target;
|
|
|
|
- console.log('element-1-dataset', (element as HTMLElement).dataset);
|
|
|
|
- console.log('element-2', (element as HTMLElement).getAttribute('class'));
|
|
|
|
- // this._sdk.eventer.addCssEvent(element as HTMLElement);
|
|
|
|
- // addEvent(element);
|
|
|
|
- // addEvents(element);
|
|
|
|
|
|
+ // const element: Node = mutation.target;
|
|
|
|
+ nodeGroup.push(Array.from(mutation.addedNodes));
|
|
|
|
+ });
|
|
|
|
+ Array.from(nodeGroup.flat()).forEach((item: Node) => {
|
|
|
|
+ // console.log('element-nodeGroup', item);
|
|
|
|
+ if ('getAttribute' in (item as HTMLElement)) {
|
|
|
|
+ this._sdk.eventer.addCssEvent(item as HTMLElement);
|
|
|
|
+ }
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|