-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move utils away from root directory (#3028)
Co-authored-by: srwang <[email protected]>
- Loading branch information
Showing
4 changed files
with
25 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
// 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 ''; | ||
} | ||
return str.charAt(0).toUpperCase() + str.slice(1); | ||
} | ||
|
||
module.exports = { capitalize }; | ||
module.exports = { sendTrackInfo, capitalize }; |