This repository was archived by the owner on Apr 29, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathactive-users.js
More file actions
69 lines (69 loc) · 3.05 KB
/
Copy pathactive-users.js
File metadata and controls
69 lines (69 loc) · 3.05 KB
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
! function(t) {
function i(s) {
if (e[s]) return e[s].exports;
var n = e[s] = {
exports: {},
id: s,
loaded: !1
};
return t[s].call(n.exports, n, n.exports, i), n.loaded = !0, n.exports
}
var e = {};
return i.m = t, i.c = e, i.p = "", i(0)
}([function(t, i) {
"use strict";
gapi.analytics.ready(function() {
gapi.analytics.createComponent("ActiveUsers", {
initialize: function() {
this.activeUsers = 0, gapi.analytics.auth.once("signOut", this.handleSignOut_.bind(this))
},
execute: function() {
this.polling_ && this.stop(), this.render_(), gapi.analytics.auth.isAuthorized() ? this.pollActiveUsers_() : gapi.analytics.auth.once("signIn", this.pollActiveUsers_.bind(this))
},
stop: function() {
clearTimeout(this.timeout_), this.polling_ = !1, this.emit("stop", {
activeUsers: this.activeUsers
})
},
render_: function() {
var t = this.get();
this.container = "string" == typeof t.container ? document.getElementById(t.container) : t.container, this.container.innerHTML = this.activeUsers
},
pollActiveUsers_: function() {
var t = this.get(),
i = 1e3 * (t.pollingInterval || 5);
if (isNaN(i) || 5e3 > i) throw new Error("Frequency must be 5 seconds or more.");
this.polling_ = !0, gapi.client.analytics.data.realtime.get({
ids: t.ids,
metrics: "rt:activeUsers"
}).then(function(t) {
var e = t.result,
s = e.totalResults ? +e.rows[0][0] : 0,
n = this.activeUsers;
this.emit("success", {
activeUsers: this.activeUsers
}), s != n && (this.activeUsers = s, this.onChange_(s - n)), 1 == this.polling_ && (this.timeout_ = setTimeout(this.pollActiveUsers_.bind(this), i))
}.bind(this))
},
onChange_: function(t) {
var i = this.container;
i && (i.innerHTML = this.activeUsers), this.emit("change", {
activeUsers: this.activeUsers,
delta: t
}), t > 0 ? this.emit("increase", {
activeUsers: this.activeUsers,
delta: t
}) : this.emit("decrease", {
activeUsers: this.activeUsers,
delta: t
})
},
handleSignOut_: function() {
this.stop(), gapi.analytics.auth.once("signIn", this.handleSignIn_.bind(this))
},
handleSignIn_: function() {
this.pollActiveUsers_(), gapi.analytics.auth.once("signOut", this.handleSignOut_.bind(this))
}
})
})
}]);