-
Notifications
You must be signed in to change notification settings - Fork 62
/
hits.js
69 lines (55 loc) · 1.54 KB
/
hits.js
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
58
59
60
61
62
63
64
65
66
67
68
69
export class Serializable {
constructor(props) {
this.properties = props || {};
}
toObject() {
return this.properties;
}
toString() {
return JSON.stringify(this.toObject());
}
toJSON() {
return JSON.stringify(this.properties);
}
toQueryString() {
var str = [];
var obj = this.toObject();
for (var p in obj) {
if (obj.hasOwnProperty(p) && obj[p]) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
}
}
return str.join('&');
}
}
class Hit extends Serializable {
sent = false
constructor(props){
super(props);
}
}
export class PageHit extends Hit {
constructor(screenName, screenTitle) {
super({ dt: screenName, dp: screenTitle || screenName, t: 'pageview' });
}
}
export class ScreenHit extends Hit {
constructor(screenName) {
super({ cd: screenName, t: 'screenview' });
}
}
export class Event extends Hit {
constructor(category, action, label, value) {
super({ ec: category, ea: action, el: label, ev: value, t: 'event' });
}
}
export class Transaction extends Hit {
constructor(id, affiliation, revenue, shipping, tax) {
super({ ti: id, ta: affiliation, tr: revenue, tt: tax, t: 'transaction' });
}
}
export class AddItem extends Hit {
constructor(id, name, price, quantity, sku, category) {
super({ti: id, in: name, ip: price, iq: quantity, ic: sku, iv: category, t: 'item' });
}
}