-
Notifications
You must be signed in to change notification settings - Fork 2
/
Page.ts
57 lines (48 loc) · 1.51 KB
/
Page.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { DL_API_ITEM } from '../enum/FlagshipConstant.ts'
import { HitType } from '../enum/HitType.ts'
import { HitAbstract, IHitAbstract } from './HitAbstract.ts'
export const ERROR_MESSAGE = 'documentLocation url is required'
export interface IPage extends IHitAbstract{
documentLocation:string
}
export class Page extends HitAbstract implements IPage {
private _documentLocation!: string
public get documentLocation (): string {
return this._documentLocation
}
public set documentLocation (v: string) {
if (!this.isNotEmptyString(v, 'documentLocation')) {
return
}
this._documentLocation = v
}
public constructor (page:Omit<IPage, 'type'|'createdAt'|'visitorInstanceId'|'traffic'>) {
super({
type: HitType.PAGE_VIEW,
userIp: page.userIp,
screenResolution: page.screenResolution,
locale: page.locale,
sessionNumber: page.sessionNumber,
visitorId: page.visitorId,
anonymousId: page.anonymousId
})
this.documentLocation = page.documentLocation
}
public isReady (checkParent = true):boolean {
return !!((!checkParent || super.isReady()) && this.documentLocation)
}
public toApiKeys ():Record<string, unknown> {
const apiKeys = super.toApiKeys()
apiKeys[DL_API_ITEM] = this.documentLocation
return apiKeys
}
public toObject ():Record<string, unknown> {
return {
...super.toObject(),
documentLocation: this.documentLocation
}
}
public getErrorMessage (): string {
return ERROR_MESSAGE
}
}