Skip to content

Commit

Permalink
chore: disable v1 analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
sandor-trombitas committed Nov 7, 2024
1 parent 60a0011 commit 6f0cb5a
Showing 1 changed file with 5 additions and 49 deletions.
54 changes: 5 additions & 49 deletions src/lib/analytics/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import * as createDebug from 'debug';
import * as needle from 'needle';
import stripAnsi = require('strip-ansi');
import { getAuthHeader, someTokenExists } from '../api-token';
import config from '../config';
import { makeRequest } from '../request';
import { config as userConfig } from '../user-config';
import { getStandardData } from './getStandardData';

// Add flags whose values should be redacted in analytics here.
// TODO make this less error-prone by baking the concept of sensitivity into the
Expand Down Expand Up @@ -68,52 +65,11 @@ export function allowAnalytics(): boolean {
* given by the data parameter, or called from {@link addDataAndSend}.
* @param customData the analytics data to send to the backend.
*/
async function postAnalytics(
customData,
): Promise<void | { res: needle.NeedleResponse; body: any }> {
// if the user opt'ed out of analytics, then let's bail out early
// ths applies to all sending to protect user's privacy
if (!allowAnalytics()) {
debug('analytics disabled');
return Promise.resolve();
}

try {
const standardData = await getStandardData(customData.args);
const analyticsData = {
...customData,
...standardData,
};
debug('analytics', JSON.stringify(analyticsData, null, ' '));

const headers = {};
if (someTokenExists()) {
headers['authorization'] = getAuthHeader();
}

const queryStringParams = {};
if (analyticsData.org) {
queryStringParams['org'] = analyticsData.org;
}

const queryString =
Object.keys(queryStringParams).length > 0 ? queryStringParams : undefined;

const res = await makeRequest({
body: {
data: analyticsData,
},
qs: queryString,
url: config.API + '/analytics/cli',
json: true,
method: 'post',
headers: headers,
});

return res;
} catch (err) {
debug('analytics', err); // this swallows the analytics error
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function postAnalytics(customData: Record<string, unknown>): Promise<void | { res: needle.NeedleResponse; body: any }> {
// Analytics disabled until we can migrate to v2 analytics
debug('analytics disabled');
return Promise.resolve();
}

/**
Expand Down

0 comments on commit 6f0cb5a

Please sign in to comment.