Skip to content

Commit 9486e80

Browse files
dvdksnclaude
andcommitted
analytics: add Marlin SDK and migrate dropdown Heap markers
Introduces @docker/marlin-sdk-web-public for first-party pageview and click analytics, bundled into scripts.js via Hugo's existing js.Build pipeline. Config is emitted to window.__marlinConfig from head.html and gated to prod/staging only. Renames data-heap-id attributes on the markdown-dropdown buttons to marlin-action so they are picked up by the SDK's auto-click tracking. TODO: replace the REPLACE-ME endpoint placeholders in hugo.yaml with the canonical Marlin ingestion URLs from the data-platform team. TODO: heap.track() calls in youtube-script.html are left in place — the public SDK exposes no equivalent track() method, so video play/pause events cannot be migrated yet. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 807a8ec commit 9486e80

6 files changed

Lines changed: 117 additions & 4 deletions

File tree

assets/js/src/marlin.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Marlin, Environment } from "@docker/marlin-sdk-web-public";
2+
3+
const config = window.__marlinConfig;
4+
5+
if (config && config.apiKey && config.endpoint) {
6+
try {
7+
window.marlin = new Marlin({
8+
endpoint: config.endpoint,
9+
apiKey: config.apiKey,
10+
site: "docs",
11+
environment:
12+
config.environment === "staging"
13+
? Environment.STAGING
14+
: Environment.PROD,
15+
});
16+
} catch (err) {
17+
console.warn("Marlin SDK init failed:", err);
18+
}
19+
}

hugo.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ params:
142142
google: GTM-WL2QLG5
143143
onetrust: 65425fb0-7b36-4317-9f10-7b3e08039af0
144144
vwo: 723167
145+
marlin:
146+
# Public-write API keys for the Marlin analytics SDK.
147+
apiKey:
148+
prod: mrl_2nuEKUo5bzRv8GcDKeYjij4J4U--OLdN
149+
stage: mrl_W14SGEQ7nYmBsAyjZPyOM-nlgE53E-vX
150+
# TODO: replace placeholder endpoints with the canonical Marlin
151+
# ingestion URLs from the data-platform team.
152+
endpoint:
153+
prod: https://REPLACE-ME.marlin.docker.com
154+
stage: https://REPLACE-ME.marlin.staging.docker.com
145155

146156
# Docs repository URL
147157
repo: https://github.com/docker/docs

layouts/_partials/head.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@
6767
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
6868
</script>
6969
{{ end }}
70+
{{- with site.Params.analytics.marlin -}}
71+
{{- $apiKey := "" -}}
72+
{{- $endpoint := "" -}}
73+
{{- $env := "" -}}
74+
{{- if hugo.IsProduction -}}
75+
{{- $apiKey = .apiKey.prod -}}
76+
{{- $endpoint = .endpoint.prod -}}
77+
{{- $env = "prod" -}}
78+
{{- else if eq hugo.Environment "staging" -}}
79+
{{- $apiKey = .apiKey.stage -}}
80+
{{- $endpoint = .endpoint.stage -}}
81+
{{- $env = "staging" -}}
82+
{{- end -}}
83+
{{- if and $apiKey $endpoint -}}
84+
<script>
85+
window.__marlinConfig = {
86+
apiKey: {{ $apiKey | jsonify }},
87+
endpoint: {{ $endpoint | jsonify }},
88+
environment: {{ $env | jsonify }}
89+
};
90+
</script>
91+
{{- end -}}
92+
{{- end -}}
7093
{{/* preload Roboto Flex as it's a critical font: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload */}}
7194
<link
7295
href="/assets/fonts/RobotoFlex.woff2"

layouts/_partials/md-dropdown.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="flex flex-wrap items-center gap-x-6 gap-y-2 text-sm">
33
<button
44
onclick="askGordon()"
5-
data-heap-id="ask-gordon-button"
5+
marlin-action="ask-gordon-button"
66
class="inline-flex cursor-pointer items-center gap-1.5 text-gray-600 transition-colors hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100"
77
>
88
<span class="icon-svg icon-sm -translate-y-px">
@@ -13,7 +13,7 @@
1313

1414
<button
1515
onclick="copyMarkdown()"
16-
data-heap-id="copy-markdown-button"
16+
marlin-action="copy-markdown-button"
1717
class="inline-flex cursor-pointer items-center gap-1.5 text-gray-600 transition-colors hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100"
1818
>
1919
<span class="icon-svg icon-sm">
@@ -27,7 +27,7 @@
2727

2828
<button
2929
onclick="viewPlainText()"
30-
data-heap-id="view-markdown-button"
30+
marlin-action="view-markdown-button"
3131
class="inline-flex cursor-pointer items-center gap-1.5 text-gray-600 transition-colors hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100"
3232
>
3333
<span class="icon-svg icon-sm">
@@ -51,7 +51,7 @@
5151
.then((text) => {
5252
navigator.clipboard.writeText(text).then(() => {
5353
const button = document.querySelector(
54-
'[data-heap-id="copy-markdown-button"]',
54+
'[marlin-action="copy-markdown-button"]',
5555
);
5656
if (!button) return;
5757

package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@alpinejs/collapse": "3.15.8",
1818
"@alpinejs/focus": "3.15.8",
1919
"@alpinejs/persist": "3.15.8",
20+
"@docker/marlin-sdk-web-public": "0.2.0",
2021
"@floating-ui/dom": "1.7.6",
2122
"@tailwindcss/cli": "4.2.1",
2223
"@tailwindcss/typography": "0.5.19",

0 commit comments

Comments
 (0)