From 3759c2885e5095bc1ab140753ec2fadd26719829 Mon Sep 17 00:00:00 2001 From: ivanThePleasant Date: Tue, 6 Sep 2022 09:07:11 +0300 Subject: [PATCH] Change analytics url endpoint, refactor all senders to the new api format --- packages/core/admin/admin/src/pages/App/index.js | 10 ++++------ .../helper-plugin/lib/src/hooks/useTracking/index.js | 10 ++++------ packages/core/strapi/lib/commands/opt-in-telemetry.js | 6 ++---- packages/core/strapi/lib/commands/opt-out-telemetry.js | 6 ++---- .../lib/services/metrics/__tests__/index.test.js | 2 +- packages/core/strapi/lib/services/metrics/sender.js | 2 +- packages/core/strapi/lib/utils/success.js | 2 +- packages/generators/app/lib/utils/usage.js | 6 +++--- 8 files changed, 18 insertions(+), 26 deletions(-) diff --git a/packages/core/admin/admin/src/pages/App/index.js b/packages/core/admin/admin/src/pages/App/index.js index 0681abee35..be9074622f 100644 --- a/packages/core/admin/admin/src/pages/App/index.js +++ b/packages/core/admin/admin/src/pages/App/index.js @@ -93,18 +93,16 @@ function App() { setTelemetryProperties(properties); try { - fetch('https://analytics.strapi.io/track', { + fetch('https://analytics.strapi.io/api/v2/track', { method: 'POST', body: JSON.stringify({ // This event is anonymous event: 'didInitializeAdministration', adminUserId: '', deviceId, - properties: { - eventPropeties: {}, - userProperties: { environment: appInfo.currentEnvironment }, - groupProperties: { ...properties, projectId: uuid }, - }, + eventPropeties: {}, + userProperties: { environment: appInfo.currentEnvironment }, + groupProperties: { ...properties, projectId: uuid }, }), headers: { 'Content-Type': 'application/json', diff --git a/packages/core/helper-plugin/lib/src/hooks/useTracking/index.js b/packages/core/helper-plugin/lib/src/hooks/useTracking/index.js index aab68fb04b..7f820d8753 100644 --- a/packages/core/helper-plugin/lib/src/hooks/useTracking/index.js +++ b/packages/core/helper-plugin/lib/src/hooks/useTracking/index.js @@ -12,15 +12,13 @@ const useTracking = () => { trackRef.current = (event, properties) => { if (uuid) { try { - axios.post('https://analytics.strapi.io/track', { + axios.post('https://analytics.strapi.io/api/v2/track', { event, adminUserId, deviceId, - properties: { - eventProperties: { ...properties }, - userProperties: {}, - groupProperties: { ...telemetryProperties }, - }, + eventProperties: { ...properties }, + userProperties: {}, + groupProperties: { ...telemetryProperties }, }); } catch (err) { // Silent diff --git a/packages/core/strapi/lib/commands/opt-in-telemetry.js b/packages/core/strapi/lib/commands/opt-in-telemetry.js index ed2ed07c09..f562de6512 100644 --- a/packages/core/strapi/lib/commands/opt-in-telemetry.js +++ b/packages/core/strapi/lib/commands/opt-in-telemetry.js @@ -53,14 +53,12 @@ const generateNewPackageJSON = (packageObj) => { const sendEvent = async (uuid) => { try { - await fetch('https://analytics.strapi.io/track', { + await fetch('https://analytics.strapi.io/api/v2/track', { method: 'POST', body: JSON.stringify({ event: 'didOptInTelemetry', deviceId: machineID(), - properties: { - groupProperties: { projectId: uuid }, - }, + groupProperties: { projectId: uuid }, }), headers: { 'Content-Type': 'application/json' }, }); diff --git a/packages/core/strapi/lib/commands/opt-out-telemetry.js b/packages/core/strapi/lib/commands/opt-out-telemetry.js index 06583f337c..3ec7dc1f24 100644 --- a/packages/core/strapi/lib/commands/opt-out-telemetry.js +++ b/packages/core/strapi/lib/commands/opt-out-telemetry.js @@ -28,14 +28,12 @@ const writePackageJSON = async (path, file, spacing) => { const sendEvent = async (uuid) => { try { - await fetch('https://analytics.strapi.io/track', { + await fetch('https://analytics.strapi.io/api/v2/track', { method: 'POST', body: JSON.stringify({ event: 'didOptOutTelemetry', deviceId: machineID(), - properties: { - groupProperties: { projectId: uuid }, - }, + groupProperties: { projectId: uuid }, }), headers: { 'Content-Type': 'application/json' }, }); diff --git a/packages/core/strapi/lib/services/metrics/__tests__/index.test.js b/packages/core/strapi/lib/services/metrics/__tests__/index.test.js index ec7e0a6353..46878e3f53 100644 --- a/packages/core/strapi/lib/services/metrics/__tests__/index.test.js +++ b/packages/core/strapi/lib/services/metrics/__tests__/index.test.js @@ -94,7 +94,7 @@ describe('metrics', () => { send('someEvent'); expect(fetch).toHaveBeenCalled(); - expect(fetch.mock.calls[0][0]).toBe('https://analytics.strapi.io/track'); + expect(fetch.mock.calls[0][0]).toBe('https://analytics.strapi.io/api/v2/track'); expect(fetch.mock.calls[0][1].method).toBe('POST'); expect(JSON.parse(fetch.mock.calls[0][1].body)).toMatchObject({ event: 'someEvent', diff --git a/packages/core/strapi/lib/services/metrics/sender.js b/packages/core/strapi/lib/services/metrics/sender.js index d3fd1ac985..5211ebf25a 100644 --- a/packages/core/strapi/lib/services/metrics/sender.js +++ b/packages/core/strapi/lib/services/metrics/sender.js @@ -82,7 +82,7 @@ module.exports = (strapi) => { }; try { - const res = await fetch(`${ANALYTICS_URI}/track`, reqParams); + const res = await fetch(`${ANALYTICS_URI}/api/v2/track`, reqParams); return res.ok; } catch (err) { return false; diff --git a/packages/core/strapi/lib/utils/success.js b/packages/core/strapi/lib/utils/success.js index 231442f0fb..ddd30c4af8 100644 --- a/packages/core/strapi/lib/utils/success.js +++ b/packages/core/strapi/lib/utils/success.js @@ -17,7 +17,7 @@ try { process.env.npm_config_global === 'true' || JSON.parse(process.env.npm_config_argv).original.includes('global') ) { - fetch('https://analytics.strapi.io/track', { + fetch('https://analytics.strapi.io/api/v2/track', { method: 'POST', body: JSON.stringify({ event: 'didInstallStrapi', diff --git a/packages/generators/app/lib/utils/usage.js b/packages/generators/app/lib/utils/usage.js index 4055b6348e..99ff5c03b0 100644 --- a/packages/generators/app/lib/utils/usage.js +++ b/packages/generators/app/lib/utils/usage.js @@ -87,7 +87,7 @@ function trackEvent(event, payload) { } try { - return fetch('https://analytics.strapi.io/track', { + return fetch('https://analytics.strapi.io/api/v2/track', { method: 'POST', body: JSON.stringify({ event, @@ -108,7 +108,7 @@ function trackError({ scope, error }) { try { return trackEvent('didNotCreateProject', { deviceId: scope.deviceId, - properties, + ...properties, }); } catch (err) { /** ignore errors */ @@ -122,7 +122,7 @@ function trackUsage({ event, scope, error }) { try { return trackEvent(event, { deviceId: scope.deviceId, - properties, + ...properties, }); } catch (err) { /** ignore errors */