Skip to content

Commit 2bce053

Browse files
authored
Set Start Free Trial click as Algolia conversion event (#5575)
* Set Start Free Trial click as Algolia conversion event * comments
1 parent 1f6139b commit 2bce053

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

docusaurus.config.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ module.exports = {
2727
stylesheets: [
2828
'https://fonts.googleapis.com/css?family=Material+Icons',
2929
],
30+
clientModules: [
31+
require.resolve('./src/client-modules/trackTrialClick.js'),
32+
],
3033
future: {
3134
v4: true,
3235
experimental_faster: true,
@@ -267,11 +270,6 @@ module.exports = {
267270
apiKey: 'fb2f4e1fb40f962900631121cb365549',
268271
indexName: 'crawler_sumodocs',
269272
contextualSearch: false,
270-
// Optional: path for search page that enabled by default (`false` to disable it)
271-
//searchPagePath: false,
272-
getMissingResultsUrl({ query }) {
273-
return `https://github.com/SumoLogic/sumologic-documentation/issues/new?title=${query}`;
274-
},
275273
insights: true,
276274
},
277275
prism: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
"repeat-string": "1.6.1",
152152
"sass": "^1.44.0",
153153
"sass-loader": "^12.4.0",
154+
"search-insights": "^2.17.3",
154155
"serve-handler": "6.1.6",
155156
"shelljs": "^0.9.0",
156157
"snake-case": "3.0.4",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Docusaurus client-module:
3+
* – executed only in the browser
4+
* – loaded once per page load
5+
*/
6+
function addListener(btn) {
7+
if (btn.__trialHooked) return;
8+
btn.__trialHooked = true;
9+
10+
btn.addEventListener('click', () => {
11+
/* Generic conversion event – *no* search context required */
12+
fetch('https://insights.algolia.io/1/events', {
13+
method: 'POST',
14+
headers: {
15+
'Content-Type': 'application/json',
16+
'X-Algolia-API-Key': 'fb2f4e1fb40f962900631121cb365549',
17+
'X-Algolia-Application-Id':'2SJPGMLW1Q',
18+
},
19+
body: JSON.stringify({
20+
events: [{
21+
eventName: 'Start Trial Button Clicked',
22+
eventType: 'conversion',
23+
index: 'crawler_sumodocs',
24+
objectIDs: ['free-trial-click'], // placeholder
25+
userToken: 'anonymous-user', // placeholder until we set up userToken/cookies auth
26+
}],
27+
}),
28+
})
29+
.then(r => r.ok ? r.json() : Promise.reject(r))
30+
.then(b => console.log('✅ Algolia Insights', b))
31+
.catch(e => console.error('❌ Algolia error', e));
32+
});
33+
34+
console.log('▶ trackTrialClick: wired');
35+
}
36+
37+
/* ---------- retry helper ---------- */
38+
function waitForButton(retries = 20) {
39+
const btn = document.querySelector('a.header-trial'); // <a class="header-trial">
40+
if (btn) return addListener(btn);
41+
42+
if (retries > 0) {
43+
return setTimeout(() => waitForButton(retries - 1), 300);
44+
}
45+
console.warn('trackTrialClick: free-trial button not found');
46+
}
47+
48+
/* run after the first page load */
49+
export function onClientEntry() {
50+
waitForButton();
51+
}
52+
53+
/* run after every client-side navigation (e.g., clicking a doc link) */
54+
export function onRouteDidUpdate() {
55+
waitForButton();
56+
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12469,6 +12469,11 @@ schema-utils@^4.0.0, schema-utils@^4.0.1, schema-utils@^4.3.0, schema-utils@^4.3
1246912469
ajv-formats "^2.1.1"
1247012470
ajv-keywords "^5.1.0"
1247112471

12472+
search-insights@^2.17.3:
12473+
version "2.17.3"
12474+
resolved "https://registry.yarnpkg.com/search-insights/-/search-insights-2.17.3.tgz#8faea5d20507bf348caba0724e5386862847b661"
12475+
integrity sha512-RQPdCYTa8A68uM2jwxoY842xDhvx3E5LFL1LxvxCNMev4o5mLuokczhzjAgGwUZBAmOKZknArSxLKmXtIi2AxQ==
12476+
1247212477
section-matter@^1.0.0:
1247312478
version "1.0.0"
1247412479
resolved "https://registry.yarnpkg.com/section-matter/-/section-matter-1.0.0.tgz#e9041953506780ec01d59f292a19c7b850b84167"

0 commit comments

Comments
 (0)