|
1 | 1 | const xhr = new XMLHttpRequest();
|
2 |
| - |
3 |
| - |
| 2 | +const TRACK_EVENT_TYPE = "track" |
| 3 | +const IDENTIFY_EVENT_TYPE = "identify" |
| 4 | +const BASE_ANALYTIC_MSG = { |
| 5 | + method: "POST", |
| 6 | + mode: "cors", |
| 7 | + cache: "no-cache", |
| 8 | + headers: { |
| 9 | + "Content-Type": "application/json", |
| 10 | + |
| 11 | + }, |
| 12 | + redirect: "follow", |
| 13 | + referrerPolicy: "no-referrer" |
| 14 | +} |
4 | 15 | xhr.onload = function () {
|
5 | 16 |
|
6 | 17 | if (xhr.readyState === XMLHttpRequest.DONE) {
|
@@ -75,44 +86,31 @@ function sendStats(name, prop) {
|
75 | 86 | }
|
76 | 87 |
|
77 | 88 | function enableSegmentBackend(version, ClusterMode) {
|
78 |
| - sendToSegmentThroughAPI("helm dashboard loaded", {version, 'installationMode': ClusterMode ? "cluster" : "local"}) |
| 89 | + sendToSegmentThroughAPI("helm dashboard loaded", {version, 'installationMode': ClusterMode ? "cluster" : "local"}, TRACK_EVENT_TYPE) |
79 | 90 | }
|
80 | 91 |
|
81 |
| -function sendToSegmentThroughAPI(eventName, properties) { |
82 |
| - if (window.heap) { |
| 92 | +function sendToSegmentThroughAPI(eventName, properties, segmentCallType) { |
83 | 93 | const userId = getUserId();
|
84 | 94 | try {
|
85 |
| - sendData(properties, "track", userId, eventName); |
| 95 | + sendData(properties, segmentCallType, userId, eventName); |
86 | 96 | } catch (e) {
|
87 | 97 | console.log("failed sending data to segment", e);
|
88 | 98 | }
|
89 |
| - } |
90 | 99 | }
|
91 | 100 |
|
92 | 101 | function sendData(data, eventType, userId, eventName) {
|
93 | 102 | const body = createBody(eventType, userId, data, eventName);
|
94 |
| - ANALYTICS_ADMIN_USER_EMAIL = "[email protected]" |
95 |
| - const auth_skipper = ANALYTICS_ADMIN_USER_EMAIL; |
96 | 103 | return fetch(`https://api.komodor.com/analytics/segment/${eventType}`, {
|
97 |
| - method: "POST", |
98 |
| - mode: "cors", |
99 |
| - cache: "no-cache", |
100 |
| - //credentials: "include", |
101 |
| - headers: { |
102 |
| - "Content-Type": "application/json", |
103 |
| - "api-key": auth_skipper, |
104 |
| - }, |
105 |
| - redirect: "follow", |
106 |
| - referrerPolicy: "no-referrer", |
| 104 | + ...BASE_ANALYTIC_MSG, |
107 | 105 | body: JSON.stringify(body),
|
108 | 106 | });
|
109 | 107 | }
|
110 | 108 |
|
111 | 109 | function createBody(segmentCallType, userId, params, eventName) {
|
112 | 110 | const data = {userId: userId};
|
113 |
| - if (segmentCallType === "identify") { |
| 111 | + if (segmentCallType === IDENTIFY_EVENT_TYPE) { |
114 | 112 | data["traits"] = params;
|
115 |
| - } else if (segmentCallType === "track") { |
| 113 | + } else if (segmentCallType === TRACK_EVENT_TYPE) { |
116 | 114 | if (!eventName) {
|
117 | 115 | throw new Error("no eventName parameter on segment track call");
|
118 | 116 | }
|
|
0 commit comments