Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.

Commit eaaa04a

Browse files
committed
Send anonymous usage data to mixpanel
Fixes #124
1 parent bc6b957 commit eaaa04a

File tree

9 files changed

+7347
-106
lines changed

9 files changed

+7347
-106
lines changed

dist/module.js

Lines changed: 7307 additions & 94 deletions
Large diffs are not rendered by default.

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/partials/config.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ <h6>Uploaded Key Details</h6>
8989
<input type="text" class="gf-form-input max-width-12" disabled="disabled" value="configured">
9090
</div>
9191

92-
<div class="gf-form width-18">
92+
93+
94+
<div class="gf-form width-18">
9395
<a class="btn btn-secondary gf-form-btn" href="#" ng-click="ctrl.resetValidationMessages()">Reset Service
9496
Account Key </a>
9597
<info-popover mode="right-normal">
@@ -101,5 +103,12 @@ <h6>Uploaded Key Details</h6>
101103
<p class="gf-form-label" ng-hide="ctrl.current.secureJsonFields.privateKey || ctrl.current.jsonData.authenticationType !== ctrl.defaultAuthenticationType"><i
102104
class="fa fa-save"></i> Do not forget to save your changes after uploading a file.</p>
103105

106+
107+
<gf-form-switch class="gf-form" label="Send anonymous usage data" label-class="width-9" checked="ctrl.current.jsonData.sendUsageData" switch-class="max-width-6"></gf-form-switch>
108+
<label class="gf-form-label query-keyword pointer">
109+
</label>
110+
111+
112+
104113
<p class="gf-form-label" ng-show="ctrl.current.jsonData.authenticationType !== ctrl.defaultAuthenticationType"><i class="fa fa-save"></i>
105114
Verify GCE default service account by clicking Save & Test</p>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"lodash-es": "^4.17.11",
2020
"moment": "^2.18.1",
2121
"q": "^1.5.1",
22-
"systemjs": "^2.1.1"
22+
"systemjs": "^2.1.1",
23+
"mixpanel-browser": "^2.29.0"
2324
},
2425
"devDependencies": {
2526
"@babel/core": "^7.4.0",

src/config_ctrl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { IJwt } from "./types";
2+
import {isCombinedModifierFlagSet} from "tslint";
23

34
export class BigQueryConfigCtrl {
45
private static templateUrl = "partials/config.html";
@@ -9,16 +10,21 @@ export class BigQueryConfigCtrl {
910
private datasourceSrv: any;
1011
private current: any;
1112
private readonly defaultAuthenticationType: string;
13+
private readonly defaultSendUsageData: boolean;
1214

1315
/** @ngInject */
1416
constructor(datasourceSrv) {
1517
this.defaultAuthenticationType = "jwt";
18+
this.defaultSendUsageData = true;
1619
this.datasourceSrv = datasourceSrv;
1720
this.current.jsonData = this.current.jsonData || {};
1821
this.current.jsonData.authenticationType = this.current.jsonData
1922
.authenticationType
2023
? this.current.jsonData.authenticationType
2124
: this.defaultAuthenticationType;
25+
if (this.current.jsonData.sendUsageData === undefined) {
26+
this.current.jsonData.sendUsageData = this.defaultSendUsageData;
27+
}
2228
this.current.secureJsonData = this.current.secureJsonData || {};
2329
this.current.secureJsonFields = this.current.secureJsonFields || {};
2430
this.authenticationTypes = [

src/datasource.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export class BigQueryDatasource {
144144
private interval: string;
145145
private readonly baseUrl: string;
146146
private readonly url: string;
147+
private mixpanel;
147148

148149
/** @ngInject */
149150
constructor(
@@ -168,6 +169,11 @@ export class BigQueryDatasource {
168169
instanceSettings.jsonData.defaultProject ||
169170
(await this.getDefaultProject());
170171
})();
172+
this.mixpanel = require("mixpanel-browser");
173+
this.mixpanel.init("86fa5c838013959cc6867dc884958f7e");
174+
if (this.jsonData.sendUsageData !== false) {
175+
this.mixpanel.track("datasource.create");
176+
}
171177
}
172178

173179
public async query(options) {
@@ -234,7 +240,7 @@ export class BigQueryDatasource {
234240
});
235241
return this.$q.all(allQueryPromise).then(
236242
(responses): any => {
237-
const data = [];
243+
const data = [];
238244
for (const response of responses) {
239245
if (response.type && response.type === "table") {
240246
data.push(response);
@@ -321,6 +327,9 @@ export class BigQueryDatasource {
321327
message = error.statusText ? error.statusText : defaultErrorMessage;
322328
}
323329
}
330+
if (this.jsonData.sendUsageData !== false) {
331+
this.mixpanel.track("datasource.save");
332+
}
324333
return {
325334
message,
326335
status

src/partials/config.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ <h6>Uploaded Key Details</h6>
8989
<input type="text" class="gf-form-input max-width-12" disabled="disabled" value="configured">
9090
</div>
9191

92-
<div class="gf-form width-18">
92+
93+
94+
<div class="gf-form width-18">
9395
<a class="btn btn-secondary gf-form-btn" href="#" ng-click="ctrl.resetValidationMessages()">Reset Service
9496
Account Key </a>
9597
<info-popover mode="right-normal">
@@ -101,5 +103,12 @@ <h6>Uploaded Key Details</h6>
101103
<p class="gf-form-label" ng-hide="ctrl.current.secureJsonFields.privateKey || ctrl.current.jsonData.authenticationType !== ctrl.defaultAuthenticationType"><i
102104
class="fa fa-save"></i> Do not forget to save your changes after uploading a file.</p>
103105

106+
107+
<gf-form-switch class="gf-form" label="Send anonymous usage data" label-class="width-9" checked="ctrl.current.jsonData.sendUsageData" switch-class="max-width-6"></gf-form-switch>
108+
<label class="gf-form-label query-keyword pointer">
109+
</label>
110+
111+
112+
104113
<p class="gf-form-label" ng-show="ctrl.current.jsonData.authenticationType !== ctrl.defaultAuthenticationType"><i class="fa fa-save"></i>
105114
Verify GCE default service account by clicking Save & Test</p>

src/query_ctrl.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@ export class BigQueryQueryCtrl extends QueryCtrl {
156156
value: "aggregate"
157157
};
158158

159-
// first and last aggregate are timescaledb specific
160-
if (this.datasource.jsonData.timescaledb === true) {
161-
aggregates.submenu.push({ text: "First", value: "first" });
162-
aggregates.submenu.push({ text: "Last", value: "last" });
163-
}
164-
165159
this.selectMenu.push(aggregates);
166160

167161
const windows = {

src/specs/datasource.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ResponseParser, { IResultFormat } from "../response_parser";
66
describe("BigQueryDatasource", () => {
77
const instanceSettings = {
88
name: "bigquery",
9-
jsonData: { authenticationType: "jwt" }
9+
jsonData: { authenticationType: "jwt", sendUsageData: false }
1010
};
1111
const backendSrv = {};
1212
const templateSrv = {

0 commit comments

Comments
 (0)