-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added Segment track for CLI scripts
- Loading branch information
1 parent
4b3e0b0
commit b46085b
Showing
4 changed files
with
27 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const axios = require('axios'); | ||
|
||
/** | ||
* Sends request to the Netlify function to inform about specified actions. | ||
* @param {string} name - tracking item name | ||
*/ | ||
function sendTrackInfo(name, trackFunctionName) { | ||
const { BASE_URL, TRACK_ANONYMOUS_ANALYTICS } = process.env; | ||
if (TRACK_ANONYMOUS_ANALYTICS) { | ||
const url = `${BASE_URL}/.netlify/functions/${trackFunctionName}`; | ||
axios.post(url, { name }) | ||
.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 }; |