diff --git a/bin/paragon-scripts.js b/bin/paragon-scripts.js index 72105dbd25..9ed5e0beda 100755 --- a/bin/paragon-scripts.js +++ b/bin/paragon-scripts.js @@ -174,7 +174,7 @@ const COMMANDS = { const [command, ...commandArgs] = process.argv.slice(2); const executor = COMMANDS[command]; - sendTrackInfo(command, 'trackCLICommands'); + sendTrackInfo('openedx.paragon.cli-command.used', { command }); if (!executor) { // eslint-disable-next-line no-console diff --git a/component-generator/index.js b/component-generator/index.js index 99db7abb9d..7f37f7bf9b 100644 --- a/component-generator/index.js +++ b/component-generator/index.js @@ -14,7 +14,7 @@ program .argument('', 'Component must have a name', validateComponentName) .action((componentName) => { // send data to analytics - sendTrackInfo(componentName, 'trackGenerateComponent'); + sendTrackInfo('openedx.paragon.functions.track-generate-component.created', { componentName }); const componentDir = path.resolve(__dirname, `../src/${componentName}`); // create directory for the component files fs.mkdirSync(componentDir); diff --git a/utils.js b/utils.js index 4481b11112..667932a4e8 100644 --- a/utils.js +++ b/utils.js @@ -2,14 +2,14 @@ const axios = require('axios'); /** * Sends request to the Netlify function to inform about specified event. - * @param {string} eventName - tracking event name - * @param {string} trackFunctionName - tracking function name + * @param {string} eventId - tracking event id + * @param {object} properties - tracking properties */ -function sendTrackInfo(eventName, trackFunctionName) { +function sendTrackInfo(eventId, properties) { const { BASE_URL, TRACK_ANONYMOUS_ANALYTICS } = process.env; if (TRACK_ANONYMOUS_ANALYTICS) { - const url = `${BASE_URL}/.netlify/functions/${trackFunctionName}`; - axios.post(url, { eventName }) + const url = `${BASE_URL}/.netlify/functions/sendTrackData`; + axios.post(url, { eventId, properties }) .then(result => { // eslint-disable-next-line no-console console.log(`Track info is successfully sent (status ${result.status})`); diff --git a/www/netlify/functions/trackCLICommands.js b/www/netlify/functions/sendAnalyticsData.js similarity index 77% rename from www/netlify/functions/trackCLICommands.js rename to www/netlify/functions/sendAnalyticsData.js index be1f9265a0..964bf57869 100644 --- a/www/netlify/functions/trackCLICommands.js +++ b/www/netlify/functions/sendAnalyticsData.js @@ -8,12 +8,12 @@ exports.handler = async function eventHandler(event) { if (event.httpMethod !== 'POST') { return { statusCode: 405, body: 'Method Not Allowed' }; } - const { eventName } = JSON.parse(event.body); + const { eventId, properties } = JSON.parse(event.body); // dispatch event to Segment analytics.track({ anonymousId: uuidv4(), - event: 'openedx.paragon.functions.track-cli-commands.run', - properties: { eventName }, + event: eventId, + properties, }); return { diff --git a/www/netlify/functions/trackGenerateComponent.js b/www/netlify/functions/trackGenerateComponent.js index 30d149d22f..8090e88369 100644 --- a/www/netlify/functions/trackGenerateComponent.js +++ b/www/netlify/functions/trackGenerateComponent.js @@ -1,23 +1,12 @@ -const { v4: uuidv4 } = require('uuid'); -const Analytics = require('analytics-node'); - -const analytics = new Analytics(process.env.SEGMENT_KEY); +const { handler: actualHandler } = require('./sendAnalyticsData'); exports.handler = async function eventHandler(event) { - // Only allow POST - if (event.httpMethod !== 'POST') { - return { statusCode: 405, body: 'Method Not Allowed' }; - } - const { eventName } = JSON.parse(event.body); - // dispatch event to Segment - analytics.track({ - anonymousId: uuidv4(), - event: 'openedx.paragon.functions.track-generate-component.created', - properties: { eventName }, + const body = JSON.parse(event.body); + event.body = JSON.stringify({ + ...body, + eventId: 'openedx.paragon.functions.track-generate-component.created', + properties: { componentName: body.componentName }, }); - return { - statusCode: 200, - body: JSON.stringify({ success: true }), - }; + return actualHandler(event); };