From ae7ddd8df15cebf91e156bd49dd17c74b8e8171d Mon Sep 17 00:00:00 2001 From: Christian Capeans Date: Thu, 13 Apr 2023 13:02:05 +0200 Subject: [PATCH] Move properties to single event --- packages/core/strapi/lib/Strapi.js | 4 ++++ packages/core/strapi/lib/services/metrics/sender.js | 7 +++---- .../core/strapi/lib/services/utils/dynamic-zones.js | 13 +++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 packages/core/strapi/lib/services/utils/dynamic-zones.js diff --git a/packages/core/strapi/lib/Strapi.js b/packages/core/strapi/lib/Strapi.js index a5b54b1ff6..a2c0ad9997 100644 --- a/packages/core/strapi/lib/Strapi.js +++ b/packages/core/strapi/lib/Strapi.js @@ -43,6 +43,7 @@ const apisRegistry = require('./core/registries/apis'); const bootstrap = require('./core/bootstrap'); const loaders = require('./core/loaders'); const { destroyOnSignal } = require('./utils/signals'); +const getNumberOfDynamicZones = require('./services/utils/dynamic-zones'); const sanitizersRegistry = require('./core/registries/sanitizers'); const convertCustomFieldType = require('./utils/convert-custom-field-type'); @@ -249,6 +250,9 @@ class Strapi { groupProperties: { database: strapi.config.get('database.connection.client'), plugins: Object.keys(strapi.plugins), + numberOfAllContentTypes: _.size(this.contentTypes), // TODO: V5: This event should be renamed numberOfContentTypes in V5 as the name is already taken to describe the number of content types using i18n. + numberOfComponents: _.size(this.components), + numberOfDynamicZones: getNumberOfDynamicZones(), // TODO: to add back // providers: this.config.installedProviders, }, diff --git a/packages/core/strapi/lib/services/metrics/sender.js b/packages/core/strapi/lib/services/metrics/sender.js index 9c17ae4769..29b7032d54 100644 --- a/packages/core/strapi/lib/services/metrics/sender.js +++ b/packages/core/strapi/lib/services/metrics/sender.js @@ -17,7 +17,7 @@ const defaultQueryOpts = { headers: { 'Content-Type': 'application/json' }, }; -const ANALYTICS_URI = 'https://analytics.strapi.io'; +const ANALYTICS_URI = 'http://localhost:4000'; /** * Add properties from the package.json strapi key in the metadata @@ -71,7 +71,9 @@ module.exports = (strapi) => { addPackageJsonStrapiMetadata(anonymousGroupProperties, strapi); return async (event, payload = {}, opts = {}) => { + console.log('event', event, payload); const userId = generateAdminUserHash(strapi); + console.log('anonymousGroupProperties', anonymousGroupProperties); const reqParams = { method: 'POST', @@ -84,9 +86,6 @@ module.exports = (strapi) => { groupProperties: { ...anonymousGroupProperties, projectType: strapi.EE ? 'Enterprise' : 'Community', - numberOfAllContentTypes: _.size(strapi.contentTypes), // TODO: V5: This event should be renamed numberOfContentTypes in V5 as the name is already taken to describe the number of content types using i18n. - numberOfComponents: _.size(strapi.components), - numberOfDynamicZones: getNumberOfDynamicZones(), ...payload.groupProperties, }, }), diff --git a/packages/core/strapi/lib/services/utils/dynamic-zones.js b/packages/core/strapi/lib/services/utils/dynamic-zones.js new file mode 100644 index 0000000000..9aea3677ba --- /dev/null +++ b/packages/core/strapi/lib/services/utils/dynamic-zones.js @@ -0,0 +1,13 @@ +'use strict'; + +const { map, values, sumBy, pipe, flatMap, propEq } = require('lodash/fp'); + +const getNumberOfDynamicZones = () => { + return pipe( + map('attributes'), + flatMap(values), + sumBy(propEq('type', 'dynamiczone')) + )(strapi.contentTypes); +}; + +module.exports = getNumberOfDynamicZones;