diff --git a/bin/paragon-scripts.js b/bin/paragon-scripts.js index 75e08a9cd8..a639a2f4f2 100755 --- a/bin/paragon-scripts.js +++ b/bin/paragon-scripts.js @@ -5,7 +5,7 @@ const helpCommand = require('../lib/help'); const buildTokensCommand = require('../lib/build-tokens'); const replaceVariablesCommand = require('../lib/replace-variables'); const buildScssCommand = require('../lib/build-scss'); -const { sendTrackInfo } = require('../utils'); +const { sendTrackInfo } = require('../lib/utils'); const versionCommand = require('../lib/version'); const commandAliases = { diff --git a/component-generator/index.js b/component-generator/index.js index 7f37f7bf9b..5929c5624d 100644 --- a/component-generator/index.js +++ b/component-generator/index.js @@ -8,7 +8,7 @@ const { addComponentToExports, addComponentToGit, } = require('./utils'); -const { sendTrackInfo } = require('../utils'); +const { sendTrackInfo } = require('../lib/utils'); program .argument('', 'Component must have a name', validateComponentName) diff --git a/lib/utils.js b/lib/utils.js index 6855ee5b27..59ada79b4a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,4 +1,25 @@ -// eslint-disable-next-line import/prefer-default-export +const axios = require('axios'); + +/** + * Sends request to the Netlify function to inform about specified event. + * @param {string} eventId - tracking event id + * @param {object} properties - tracking properties + */ +function sendTrackInfo(eventId, properties) { + const { BASE_URL, TRACK_ANONYMOUS_ANALYTICS } = process.env; + if (TRACK_ANONYMOUS_ANALYTICS) { + 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})`); + }).catch(error => { + // eslint-disable-next-line no-console + console.log(`Track info request failed (${error})`); + }); + } +} + function capitalize(str) { if (typeof str !== 'string' || str.length === 0) { return ''; @@ -6,4 +27,4 @@ function capitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); } -module.exports = { capitalize }; +module.exports = { sendTrackInfo, capitalize }; diff --git a/utils.js b/utils.js deleted file mode 100644 index 667932a4e8..0000000000 --- a/utils.js +++ /dev/null @@ -1,23 +0,0 @@ -const axios = require('axios'); - -/** - * Sends request to the Netlify function to inform about specified event. - * @param {string} eventId - tracking event id - * @param {object} properties - tracking properties - */ -function sendTrackInfo(eventId, properties) { - const { BASE_URL, TRACK_ANONYMOUS_ANALYTICS } = process.env; - if (TRACK_ANONYMOUS_ANALYTICS) { - 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})`); - }).catch(error => { - // eslint-disable-next-line no-console - console.log(`Track info request failed (${error})`); - }); - } -} - -module.exports = { sendTrackInfo };