Skip to content

Commit 3d398a4

Browse files
authored
feat: add gtm tag inside docs (#171)
1 parent ce38392 commit 3d398a4

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

docs/js/google-tag-manager.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(function (w, d, s, l, i) {
2+
w[l] = w[l] || [];
3+
w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });
4+
var f = d.getElementsByTagName(s)[0],
5+
j = d.createElement(s),
6+
dl = l != "dataLayer" ? "&l=" + l : "";
7+
j.async = true;
8+
j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;
9+
f.parentNode.insertBefore(j, f);
10+
})(window, document, "script", "dataLayer", "GTM-5RDZ55LR");

docs/js/search-tracking.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
...payload,
103103
}),
104104
});
105+
});
106+
105107
} catch (error) {
106108
console.warn("Analytics API error:", error);
107109
}
@@ -130,6 +132,7 @@
130132
function trackResultClick(resultUrl, resultTitle, resultRank) {
131133
const _q = lastSearchQuery.trim();
132134

135+
133136
// Send result_click event exactly like Vue.js reference
134137
sendAnalyticsEvent("doc-search-click", {
135138
result_url: resultUrl,
@@ -218,6 +221,7 @@
218221
let searchTimeout;
219222
let lastTrackedQuery = "";
220223

224+
221225
// Update context when search becomes active (like Vue.js modal opening)
222226
const updateContextOnSearchActivation = () => {
223227
try {
@@ -268,6 +272,7 @@
268272

269273
// Track search result clicks with enhanced logic
270274
document.addEventListener("click", function (e) {
275+
271276
// Multiple ways to detect search result clicks
272277
const isSearchResult =
273278
e.target.closest(".md-search-result__item") ||
@@ -285,6 +290,7 @@
285290
return;
286291
}
287292

293+
288294
// Check if search is active (more lenient check)
289295
const searchContainer = document.querySelector(".md-search");
290296
const searchInput = document.querySelector(".md-search__input");
@@ -301,20 +307,21 @@
301307
// Update context right before tracking click (ensure fresh data)
302308
updateContextOnSearchActivation();
303309

304-
const resultInfo = extractResultInfo(e.target);
310+
const resultInfo = extractResultInfo(e.target);
305311

306-
if (resultInfo && resultInfo.url) {
312+
if (resultInfo && resultInfo.url) {
307313
trackResultClick(resultInfo.url, resultInfo.title, resultInfo.rank);
308314
} else {
309315
console.warn("Could not extract result info from clicked element");
310316
}
311-
});
317+
});
318+
312319
}
313320

314321
/**
315322
* Initialize feedback tracking - new functionality for page feedback
316323
*/
317-
function initializeFeedbackTracking() {
324+
function initializeFeedbackTracking() {
318325

319326
// Track feedback button clicks
320327
document.addEventListener("click", function (e) {
@@ -323,7 +330,8 @@
323330

324331
if (!feedbackButton) {
325332
return;
326-
}
333+
}
334+
327335

328336
// Get feedback value from data-md-value attribute
329337
const feedbackValue = feedbackButton.getAttribute("data-md-value");
@@ -344,7 +352,7 @@
344352
// Track the feedback
345353
trackPageFeedback(feedbackValueNum, pageUrl, pageTitle);
346354
});
347-
355+
348356
}
349357

350358
/**
@@ -395,7 +403,7 @@
395403
testClickDetection: function () {
396404
const searchResults = document.querySelectorAll(
397405
".md-search-result__item, .md-search-result, [data-md-component='search-result']"
398-
);
406+
);
399407
return searchResults;
400408
},
401409
testFeedbackDetection: function () {

mkdocs.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ extra_css:
1818
- css/landing-page.css
1919
extra_javascript:
2020
- https://unpkg.com/openapi-explorer@0/dist/browser/openapi-explorer.min.js
21-
- js/ms-clarity.js
22-
- js/zinc.js
23-
- js/vector_co.js
21+
# - js/ms-clarity.js
22+
# - js/zinc.js
23+
# - js/vector_co.js
2424
- js/search-close-minimal.js
2525
- js/search-tracking.js
2626
- https://buttons.github.io/buttons.js
27-
- js/reo.js
27+
# - js/reo.js
2828
- js/landing-individual-card-ms-tracking.js
29+
- js/google-tag-manager.js
2930
extra:
3031
# social:
3132
# - icon: fontawesome/brands/linkedin

0 commit comments

Comments
 (0)