Skip to content

Commit

Permalink
feat: enable google analytics with _googleAnalyticsTagId
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih committed May 5, 2023
1 parent 2fb03c1 commit f9598e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"globalMetadata": {
"_appTitle": "docfx",
"_appName": "docfx",
"_appFooter": "<span>Supported by the <a href=\"https://dotnetfoundation.org\">.NET Foundation</a>. Made with <a href=\"https://dotnet.github.io/docfx\">docfx</a></span>"
"_appFooter": "<span>Supported by the <a href=\"https://dotnetfoundation.org\">.NET Foundation</a>. Made with <a href=\"https://dotnet.github.io/docfx\">docfx</a></span>",
"_googleTagId": "G-Q5N6XJHEX5"
},
"output": "_site",
"template": [
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Name | Type | Description
`_disableNewTab` | bool | Whether to render external link indicator icons and open external links in a new tab.
`_disableNextArticle` | bool | Whether to show the previous and next article link.
`_disableTocFilter` | bool | Whether to show the table of content filter box.
`lang` | string | Primary language of the page. If unset, the `<html>` tag will not have `lang` property.
`_googleTagId` | string | Enables Google Analytics web traffic analysis.
`lang` | string | Primary language of the page. If unset, the `<html>` tag will not have `lang` property.
`layout` | string | Determines the layout of the page. Supported values are `landing` and `chromeless`.

# [Default Template](#tab/default)
Expand Down
10 changes: 10 additions & 0 deletions templates/modern/layout/_master.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
{{/redirect_url}}
</head>

{{#_googleTagId}}
<script async src="https://www.googletagmanager.com/gtag/js?id={{_googleTagId}}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', '{{_googleTagId}}');
</script>
{{/_googleTagId}}

{{^redirect_url}}
<body class="tex2jax_ignore" data-layout="{{layout}}" data-yaml-mime="{{yamlmime}}">
<header class="bg-body border-bottom">
Expand Down

0 comments on commit f9598e8

Please sign in to comment.