Skip to content

Commit 2378a4b

Browse files
Merge pull request #391 from UiPath/docs/google-analytics
feat(docs): add google analytics
2 parents 6890077 + 6f0e14a commit 2378a4b

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

docs/hooks.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
2+
import re
23
import shutil
34

45

5-
def redirect_index(*args, **kwargs):
6+
def on_pre_build(config):
67
if not os.path.exists("docs/quick_start_images"):
78
shutil.copy(
89
"docs/plugins/uipath-langchain-python/docs/quick_start.md", "docs/index.md"
@@ -11,3 +12,9 @@ def redirect_index(*args, **kwargs):
1112
"docs/plugins/uipath-langchain-python/docs/quick_start_images",
1213
"docs/quick_start_images",
1314
)
15+
16+
17+
def on_post_page(output, page, config):
18+
pattern = r"(<body[^>]*>)"
19+
replacement = rf"\1\n<noscript><iframe src='https://www.googletagmanager.com/ns.html?id={config['google_tag_manager_id']}' height='0' width='0' style='display:none;visibility:hidden'></iframe></noscript>"
20+
return re.sub(pattern, replacement, output)

docs/overrides/main.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends "base.html" %}
2+
3+
{% block extrahead %}
4+
<!-- Google Tag Manager -->
5+
<script>(function (w, d, s, l, i) {
6+
w[l] = w[l] || []; w[l].push({
7+
'gtm.start':
8+
new Date().getTime(), event: 'gtm.js'
9+
}); var f = d.getElementsByTagName(s)[0],
10+
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
11+
'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
12+
})(window, document, 'script', 'dataLayer', '{{ config.google_tag_manager_id }}');</script>
13+
<!-- End Google Tag Manager -->
14+
{% endblock %}

mkdocs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ extra_css:
1212
extra_javascript:
1313
- javascripts/extra.js
1414

15+
google_tag_manager_id: GTM-PLLP8P
16+
1517
theme:
1618
name: material
1719
custom_dir: docs/overrides
@@ -96,7 +98,8 @@ plugins:
9698
show_bases: false
9799
- mkdocs-simple-hooks:
98100
hooks:
99-
on_pre_build: "docs.hooks:redirect_index"
101+
on_pre_build: "docs.hooks:on_pre_build"
102+
on_post_page: "docs.hooks:on_post_page"
100103
- termynal:
101104
prompt_literal_start:
102105
- "$"

0 commit comments

Comments
 (0)