Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/userGuide/plugins/googleAnalytics.mbdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#### `Google Analytics`: Enhancing site with Google Analytics

This plugin allows your web pages to be enhanced with [google analytics](https://analytics.google.com/analytics/web/#/) to track, analyse and improve your content.

To enable it, add `googleAnalytics` to your site's plugins, and add the trackingID parameter via the `pluginsContext`.

Name | Type | Default | Description
---- | ---- | ------- | ------
trackingID | `String` || Tracking ID provided by Google. Follow this [guide](https://support.google.com/analytics/answer/1008080) to get your Tracking ID.

```js
site.json
{
...
"plugins": [
"googleAnalytics"
],
"pluginsContext": {
"googleAnalytics": {
"trackingID": "YOUR-TRACKING-ID", // replace with your google analytics tracking id.
}
}
}
```
3 changes: 2 additions & 1 deletion docs/userGuide/usingPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ Disabling the `anchors` plugin:

MarkBind has a set of built-in plugins that can be used immediately without installation.

<include src="plugins/filterTags.mbdf" />
<include src="plugins/algolia.mbdf" />
<include src="plugins/filterTags.mbdf" />
<include src="plugins/googleAnalytics.mbdf" />

{% from "njk/common.njk" import previous_next %}
{{ previous_next('usingHtmlJavaScriptCss', 'tweakingThePageStructure') }}
17 changes: 17 additions & 0 deletions src/plugins/googleAnalytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function getGoogleAnalyticsTrackingCode(pluginContext) {
return `
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=${pluginContext.trackingID}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '${pluginContext.trackingID}');
</script>`;
}

module.exports = {
// eslint-disable-next-line no-unused-vars
getScripts: (content, pluginContext, frontMatter, utils) => getGoogleAnalyticsTrackingCode(pluginContext),
};
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/bugs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ <h2 id="remove-extra-space-in-links">Remove extra space in links<a class="fa fa-
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="../markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,19 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/sub_site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ <h2 id="feature-list">Feature list<a class="fa fa-anchor" href="#feature-list"><
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="../markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testAfterSetup.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/testAfterSetup/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testAnchorGeneration.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ <h6 id="should-have-anchor-24">should have anchor<a class="fa fa-anchor" href="#
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testAntiFOUCStyles.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ <h1 id="filler-text">Filler text<a class="fa fa-anchor" href="#filler-text"></a>
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testEmptyFrontmatter.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testExternalScripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testLayouts.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ <h1 id="uses-a-front-matter-layout">Uses a front matter layout<a class="fa fa-an
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/testLayout/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testLayoutsOverride.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ <h1 id="uses-a-site-json-layout-overriding-front-matter">Uses a site.json layout
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/testLayout/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testPlantUML.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ <h3 id="object-diagram">Object Diagram<a class="fa fa-anchor" href="#object-diag
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testThumbnails.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ <h3 id="font-color">font-color<a class="fa fa-anchor" href="#font-color"></a></h
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/testTooltipSpacing.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ <h1 id="569-stray-space-after-tooltip">569: Stray space after tooltip<a class="f
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
13 changes: 13 additions & 0 deletions test/functional/test_site/expected/test_md_fragment.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ <h1 id="some-heading">Some heading<a class="fa fa-anchor" href="#some-heading"><
<script>
alert("hello")
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TRACKING-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];

function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'TRACKING-ID');
</script>
<script src="markbind/layouts/default/scripts.js"></script>

</html>
6 changes: 5 additions & 1 deletion test/functional/test_site/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"headingIndexingLevel": 4,
"plugins": [
"testMarkbindPlugin",
"filterTags"
"filterTags",
"googleAnalytics"
],
"pluginsContext": {
"testMarkbindPlugin": {
Expand All @@ -95,6 +96,9 @@
},
"filterTags": {
"tags": ["tag-site-shown", "+tag-site-override-shown", "+tag-site-override-specific-shown"]
},
"googleAnalytics": {
"trackingID": "TRACKING-ID"
}
}
}