diff --git a/docusaurus.config.js b/docusaurus.config.js index c8e28ed999..99a4b20ef6 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -27,6 +27,9 @@ module.exports = { stylesheets: [ 'https://fonts.googleapis.com/css?family=Material+Icons', ], + scripts: [ + { src: '/track-trial-click.js', async: true }, + ], future: { v4: true, experimental_faster: true, diff --git a/static/track-trial-click.js b/static/track-trial-click.js new file mode 100644 index 0000000000..df59510870 --- /dev/null +++ b/static/track-trial-click.js @@ -0,0 +1,32 @@ +(function () { + document.addEventListener('DOMContentLoaded', function () { + const trialBtn = document.querySelector('.header-trial'); + + if (!trialBtn) return; + + trialBtn.addEventListener('click', () => { + fetch('https://insights.algolia.io/1/events', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-Algolia-API-Key': 'fb2f4e1fb40f962900631121cb365549', + 'X-Algolia-Application-Id': '2SJPGMLW1Q' + }, + body: JSON.stringify({ + events: [ + { + eventName: 'Start Free Trial Clicked', + eventType: 'conversion', + index: 'crawler_sumodocs', + objectIDs: ['trial-button-static'], // static dummy ID + userToken: 'docusaurus-user' + } + ] + }) + }) + .then(res => res.json()) + .then(console.log) + .catch(console.error); + }); + }); +})();