Skip to content

Commit a9df65f

Browse files
committed
[Docs Site] Add Zaraz events for SERP clicks
1 parent ffb6bc7 commit a9df65f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/components/404.astro

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
</div>
1010

1111
<script>
12+
import { track } from "~/util/zaraz";
13+
1214
const { pathname } = window.location;
1315

1416
const anchor = document.getElementById("404-search-link");
@@ -17,5 +19,8 @@
1719
const pretty = pathname.replaceAll("/", " ").replaceAll("-", " ").trim();
1820

1921
anchor.setAttribute("href", `/search/?q=${encodeURIComponent(pretty)}`);
22+
anchor.addEventListener("click", () => {
23+
track("serp from 404", { query: pretty });
24+
});
2025
}
2126
</script>

src/plugins/docsearch/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { track } from "~/util/zaraz";
12
import type { DocSearchClientOptions } from "@astrojs/starlight-docsearch";
23

34
export default {
@@ -26,6 +27,10 @@ export default {
2627
__v: null,
2728
key: state.query,
2829
props: {
30+
onclick: () => {
31+
track("serp from widget", { query: state.query });
32+
},
33+
id: "docsearch-search-link",
2934
href: `/search/?query=${state.query}`,
3035
target: "_blank",
3136
children: "View all results",

0 commit comments

Comments
 (0)