diff --git a/docusaurus.config.js b/docusaurus.config.js index 5ceb76315d..273e2c47c7 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -27,6 +27,9 @@ module.exports = { stylesheets: [ 'https://fonts.googleapis.com/css?family=Material+Icons', ], + clientModules: [ + require.resolve('./src/client-modules/trackTrialClick.js'), + ], future: { v4: true, experimental_faster: true, @@ -267,11 +270,6 @@ module.exports = { apiKey: 'fb2f4e1fb40f962900631121cb365549', indexName: 'crawler_sumodocs', contextualSearch: false, - // Optional: path for search page that enabled by default (`false` to disable it) - //searchPagePath: false, - getMissingResultsUrl({ query }) { - return `https://github.com/SumoLogic/sumologic-documentation/issues/new?title=${query}`; - }, insights: true, }, prism: { diff --git a/package.json b/package.json index 3917527ebd..fffa330d2f 100644 --- a/package.json +++ b/package.json @@ -151,6 +151,7 @@ "repeat-string": "1.6.1", "sass": "^1.44.0", "sass-loader": "^12.4.0", + "search-insights": "^2.17.3", "serve-handler": "6.1.6", "shelljs": "^0.9.0", "snake-case": "3.0.4", diff --git a/src/client-modules/trackTrialClick.js b/src/client-modules/trackTrialClick.js new file mode 100644 index 0000000000..e1292a5c0d --- /dev/null +++ b/src/client-modules/trackTrialClick.js @@ -0,0 +1,56 @@ +/** + * Docusaurus client-module: + * – executed only in the browser + * – loaded once per page load + */ +function addListener(btn) { + if (btn.__trialHooked) return; + btn.__trialHooked = true; + + btn.addEventListener('click', () => { + /* Generic conversion event – *no* search context required */ + 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 Trial Button Clicked', + eventType: 'conversion', + index: 'crawler_sumodocs', + objectIDs: ['free-trial-click'], // placeholder + userToken: 'anonymous-user', // placeholder until we set up userToken/cookies auth + }], + }), + }) + .then(r => r.ok ? r.json() : Promise.reject(r)) + .then(b => console.log('✅ Algolia Insights', b)) + .catch(e => console.error('❌ Algolia error', e)); + }); + + console.log('▶ trackTrialClick: wired'); +} + +/* ---------- retry helper ---------- */ +function waitForButton(retries = 20) { + const btn = document.querySelector('a.header-trial'); // + if (btn) return addListener(btn); + + if (retries > 0) { + return setTimeout(() => waitForButton(retries - 1), 300); + } + console.warn('trackTrialClick: free-trial button not found'); +} + +/* run after the first page load */ +export function onClientEntry() { + waitForButton(); +} + +/* run after every client-side navigation (e.g., clicking a doc link) */ +export function onRouteDidUpdate() { + waitForButton(); +} diff --git a/yarn.lock b/yarn.lock index 7a1f6fc3cc..09dd578f8a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12469,6 +12469,11 @@ schema-utils@^4.0.0, schema-utils@^4.0.1, schema-utils@^4.3.0, schema-utils@^4.3 ajv-formats "^2.1.1" ajv-keywords "^5.1.0" +search-insights@^2.17.3: + version "2.17.3" + resolved "https://registry.yarnpkg.com/search-insights/-/search-insights-2.17.3.tgz#8faea5d20507bf348caba0724e5386862847b661" + integrity sha512-RQPdCYTa8A68uM2jwxoY842xDhvx3E5LFL1LxvxCNMev4o5mLuokczhzjAgGwUZBAmOKZknArSxLKmXtIi2AxQ== + section-matter@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/section-matter/-/section-matter-1.0.0.tgz#e9041953506780ec01d59f292a19c7b850b84167"