diff --git a/www/netlify/functions/trackCLICommands.js b/www/netlify/functions/trackCLICommands.js new file mode 100644 index 00000000000..be1f9265a08 --- /dev/null +++ b/www/netlify/functions/trackCLICommands.js @@ -0,0 +1,23 @@ +const { v4: uuidv4 } = require('uuid'); +const Analytics = require('analytics-node'); + +const analytics = new Analytics(process.env.SEGMENT_KEY); + +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-cli-commands.run', + properties: { eventName }, + }); + + return { + statusCode: 200, + body: JSON.stringify({ success: true }), + }; +}; diff --git a/www/netlify/functions/trackGenerateComponent.js b/www/netlify/functions/trackGenerateComponent.js index b0b29ed3b3c..30d149d22ff 100644 --- a/www/netlify/functions/trackGenerateComponent.js +++ b/www/netlify/functions/trackGenerateComponent.js @@ -8,12 +8,12 @@ exports.handler = async function eventHandler(event) { if (event.httpMethod !== 'POST') { return { statusCode: 405, body: 'Method Not Allowed' }; } - const { componentName } = JSON.parse(event.body); + const { eventName } = JSON.parse(event.body); // dispatch event to Segment analytics.track({ anonymousId: uuidv4(), event: 'openedx.paragon.functions.track-generate-component.created', - properties: { componentName }, + properties: { eventName }, }); return {