Skip to content

How to inject the google analytics tracking information into the html file #272

Answered by yhatt
chenxizhang asked this question in Q&A
Discussion options

You must be logged in to vote

Place the snippet by Google Analytics into the first page of your Markdown, and output HTML in Marp CLI with enabled --html option.

<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

https://developers.google.com/analytics/devguides/collection/analyticsjs

Of course you also can make a plugin to prepend the script like this:

const script = `
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script a…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@chenxizhang
Comment options

Answer selected by chenxizhang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants