forked from ryanvanderpol/react-native-googleanalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hits.js
57 lines (45 loc) · 1.11 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
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) {
super({ dp: 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' });
}
}