Skip to content

Add Algolia conversion event #5524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ module.exports = {
stylesheets: [
'https://fonts.googleapis.com/css?family=Material+Icons',
],
scripts: [
{
src: 'https://cdn.jsdelivr.net/npm/[email protected]',
async: true,
},
],
future: {
v4: true,
experimental_faster: true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@algolia/autocomplete-preset-algolia": "1.17.9",
"@algolia/client-abtesting": "5.18.0",
"@algolia/client-analytics": "5.18.0",
"@algolia/client-insights": "5.18.0",
"@algolia/client-insights": "^5.30.0",
"@algolia/client-personalization": "5.18.0",
"@algolia/client-query-suggestions": "5.18.0",
"@algolia/client-search": "5.18.0",
Expand Down 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
43 changes: 43 additions & 0 deletions src/components/SearchConversionTracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use client';

import { useEffect } from 'react';
import aa from 'search-insights';

export default function SearchConversionTracker() {
useEffect(() => {
aa('init', {
appId: '2SJPGMLW1Q',
apiKey: 'fb2f4e1fb40f962900631121cb365549',
useCookie: true,
});

const handleClick = (event) => {
const target = event.target.closest('a[data-algolia-objectid][data-algolia-queryid][data-algolia-index]');
if (target) {
const objectID = target.getAttribute('data-algolia-objectid');
const queryID = target.getAttribute('data-algolia-queryid');
const indexName = target.getAttribute('data-algolia-index');

if (objectID && queryID && indexName) {
console.log('Sending conversion:', {
objectID,
queryID,
indexName,
});

aa('convertedObjectIDsAfterSearch', {
index: indexName,
eventName: 'Search result clicked',
queryID,
objectIDs: [objectID],
});
}
}
};

document.addEventListener('click', handleClick);
return () => document.removeEventListener('click', handleClick);
}, []);

return null;
}
2 changes: 2 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SumoLogicDocsLogo from '../../static/img/sumo-logic-docs.svg';
import { Feature } from '../components/Feature';
import { features } from '../helper/features';
import ErrorBoundary from '../components/ErrorBoundary';
import SearchConversionTracker from '../components/SearchConversionTracker';

export const Home = () => {
const [tab, setTab] = useState('0');
Expand All @@ -19,6 +20,7 @@ export const Home = () => {
description='Sumo Logic docs - real-time alerting, security, dashboards, and machine-learning-powered analytics for all three types of telemetry — logs, metrics, and traces.'
title='Home'
>
<SearchConversionTracker />
{/* Header */}
<Typography
bgcolor='#0045BE'
Expand Down
14 changes: 14 additions & 0 deletions src/theme/DocSearch/Hit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

export default function Hit({ hit, children }) {
return (
<a
href={hit.url}
data-algolia-objectid={hit.objectID}
data-algolia-queryid={hit.__queryID}
data-algolia-index={hit.__indexName}
>
{children}
</a>
);
}
49 changes: 40 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,10 @@
resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-5.27.0.tgz#290b9d0922c5a7162f6e322357a0d0a8565b939a"
integrity sha512-tnFOzdNuMzsz93kOClj3fKfuYoF3oYaEB5bggULSj075GJ7HUNedBEm7a6ScrjtnOaOtipbnT7veUpHA4o4wEQ==

"@algolia/[email protected]":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@algolia/client-insights/-/client-insights-5.18.0.tgz#2c6f158e57265fd0888f5b84fe7302d6d659c0ff"
integrity sha512-FAJRNANUOSs/FgYOJ/Njqp+YTe4TMz2GkeZtfsw1TMiA5mVNRS/nnMpxas9771aJz7KTEWvK9GwqPs0K6RMYWg==
dependencies:
"@algolia/client-common" "5.18.0"
"@algolia/requester-browser-xhr" "5.18.0"
"@algolia/requester-fetch" "5.18.0"
"@algolia/requester-node-http" "5.18.0"
"@algolia/[email protected]":
version "5.30.0"
resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-5.30.0.tgz#fa7b03095e90f7fef2d1786baec278e7125b0740"
integrity sha512-tbUgvkp2d20mHPbM0+NPbLg6SzkUh0lADUUjzNCF+HiPkjFRaIW3NGMlESKw5ia4Oz6ZvFzyREquUX6rdkdJcQ==

"@algolia/[email protected]":
version "5.27.0"
Expand All @@ -99,6 +94,16 @@
"@algolia/requester-fetch" "5.27.0"
"@algolia/requester-node-http" "5.27.0"

"@algolia/client-insights@^5.30.0":
version "5.30.0"
resolved "https://registry.yarnpkg.com/@algolia/client-insights/-/client-insights-5.30.0.tgz#e2bd9e2e4984f2e68dc6c1f881fcd3834cd9b23f"
integrity sha512-caXuZqJK761m32KoEAEkjkE2WF/zYg1McuGesWXiLSgfxwZZIAf+DljpiSToBUXhoPesvjcLtINyYUzbkwE0iw==
dependencies:
"@algolia/client-common" "5.30.0"
"@algolia/requester-browser-xhr" "5.30.0"
"@algolia/requester-fetch" "5.30.0"
"@algolia/requester-node-http" "5.30.0"

"@algolia/[email protected]":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@algolia/client-personalization/-/client-personalization-5.18.0.tgz#26128f6a1aef523ae32f29ef9afd18fd2f159b98"
Expand Down Expand Up @@ -238,6 +243,13 @@
dependencies:
"@algolia/client-common" "5.27.0"

"@algolia/[email protected]":
version "5.30.0"
resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-5.30.0.tgz#a006ed06e910b33d750173ad86feb3ca2ede1a4c"
integrity sha512-alo3ly0tdNLjfMSPz9dmNwYUFHx7guaz5dTGlIzVGnOiwLgIoM6NgA+MJLMcH6e1S7OpmE2AxOy78svlhst2tQ==
dependencies:
"@algolia/client-common" "5.30.0"

"@algolia/[email protected]":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@algolia/requester-fetch/-/requester-fetch-5.18.0.tgz#fcccc76bd7d16fb54c56d15baa6b5f657b17ca71"
Expand All @@ -252,6 +264,13 @@
dependencies:
"@algolia/client-common" "5.27.0"

"@algolia/[email protected]":
version "5.30.0"
resolved "https://registry.yarnpkg.com/@algolia/requester-fetch/-/requester-fetch-5.30.0.tgz#a118448b51ce20f703aca706709a1196dada2a28"
integrity sha512-WOnTYUIY2InllHBy6HHMpGIOo7Or4xhYUx/jkoSK/kPIa1BRoFEHqa8v4pbKHtoG7oLvM2UAsylSnjVpIhGZXg==
dependencies:
"@algolia/client-common" "5.30.0"

"@algolia/[email protected]":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-5.18.0.tgz#c5b16de53d83276067583e7b2f56b09eac938435"
Expand All @@ -266,6 +285,13 @@
dependencies:
"@algolia/client-common" "5.27.0"

"@algolia/[email protected]":
version "5.30.0"
resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-5.30.0.tgz#607f827b09da78bc2300d02e137fbbbeed11f1d3"
integrity sha512-uSTUh9fxeHde1c7KhvZKUrivk90sdiDftC+rSKNFKKEU9TiIKAGA7B2oKC+AoMCqMymot1vW9SGbeESQPTZd0w==
dependencies:
"@algolia/client-common" "5.30.0"

"@ampproject/remapping@^2.2.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.3.0.tgz#ed441b6fa600072520ce18b43d2c8cc8caecc7f4"
Expand Down Expand Up @@ -12469,6 +12495,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