Skip to content

Commit 7ec2117

Browse files
committed
Disable metrics collection if HEAP_ANALYTICS_ID not set
1 parent b49865f commit 7ec2117

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed

common/components/utils/heapApi.js

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
// @flow
22

33
export function loadHeap() {
4-
window.heap = window.heap || [];
5-
heap.load = function(e, t) {
6-
window.heap.appid = e;
7-
window.heap.config = t = t || {};
8-
let r = document.createElement("script");
9-
r.type = "text/javascript";
10-
r.async = !0;
11-
r.src = "https://cdn.heapanalytics.com/js/heap-" + e + ".js";
12-
let a = document.getElementsByTagName("script")[0];
13-
a.parentNode.insertBefore(r, a);
14-
for (
15-
let n = function(e) {
16-
return function() {
17-
heap.push([e].concat(Array.prototype.slice.call(arguments, 0)));
18-
};
19-
},
20-
p = [
21-
"addEventProperties",
22-
"addUserProperties",
23-
"clearEventProperties",
24-
"identify",
25-
"resetIdentity",
26-
"removeEventProperty",
27-
"setEventProperties",
28-
"track",
29-
"unsetEventProperty",
30-
],
31-
o = 0;
32-
o < p.length;
33-
o++
34-
)
35-
heap[p[o]] = n(p[o]);
36-
};
37-
heap.load(window.HEAP_ANALYTICS_ID);
38-
window.democracyLabEvents = { heapLoaded: true };
39-
window.dispatchEvent(new Event("heapLoaded"));
4+
if (window.HEAP_ANALYTICS_ID) {
5+
window.heap = window.heap || [];
6+
heap.load = function(e, t) {
7+
window.heap.appid = e;
8+
window.heap.config = t = t || {};
9+
let r = document.createElement("script");
10+
r.type = "text/javascript";
11+
r.async = !0;
12+
r.src = "https://cdn.heapanalytics.com/js/heap-" + e + ".js";
13+
let a = document.getElementsByTagName("script")[0];
14+
a.parentNode.insertBefore(r, a);
15+
for (
16+
let n = function(e) {
17+
return function() {
18+
heap.push([e].concat(Array.prototype.slice.call(arguments, 0)));
19+
};
20+
},
21+
p = [
22+
"addEventProperties",
23+
"addUserProperties",
24+
"clearEventProperties",
25+
"identify",
26+
"resetIdentity",
27+
"removeEventProperty",
28+
"setEventProperties",
29+
"track",
30+
"unsetEventProperty",
31+
],
32+
o = 0;
33+
o < p.length;
34+
o++
35+
)
36+
heap[p[o]] = n(p[o]);
37+
};
38+
heap.load(window.HEAP_ANALYTICS_ID);
39+
window.democracyLabEvents = { heapLoaded: true };
40+
window.dispatchEvent(new Event("heapLoaded"));
41+
}
4042
}
4143

4244
loadHeap();

common/components/utils/metrics.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ type HeapInterface = {|
2121
|};
2222

2323
function _logEvent(eventName: string, parameters: ?MetricsParameters): void {
24-
Async.onEvent("heapLoaded", () => {
25-
window.heap.track(eventName, parameters);
26-
});
24+
if (window.HEAP_ANALYTICS_ID) {
25+
Async.onEvent("heapLoaded", () => {
26+
window.heap.track(eventName, parameters);
27+
});
28+
}
2729
}
2830

2931
class metrics {

0 commit comments

Comments
 (0)