Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 56 additions & 0 deletions src/client-modules/trackTrialClick.js
Original file line number Diff line number Diff line change
@@ -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'); // <a class="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();
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down