Skip to content

Commit

Permalink
Added Google Analytics option
Browse files Browse the repository at this point in the history
  • Loading branch information
Apostolique committed Oct 6, 2023
1 parent 694ff42 commit 4672674
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
DESCRIPTION: Documentation static site generator.
BASE: apos-docs
REPO: https://github.com/Apostolique/apos-docs/tree/main/
ANALYTICS: G-TK6SK1XJRV

jobs:
build:
Expand All @@ -28,7 +29,7 @@ jobs:
uses: c-hive/gha-npm-cache@v1
- name: Use apos-docs
run: |
apos-docs -t ${{ env.TITLE }} -d '${{ env.DESCRIPTION }}' -b ${{ env.BASE }} -r ${{ env.REPO }}
apos-docs -t ${{ env.TITLE }} -d '${{ env.DESCRIPTION }}' -b ${{ env.BASE }} -r ${{ env.REPO }} -g ${{ env.ANALYTICS }}
cd apos-docs
npm install
npm run build
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ program
.option('-t, --title <title>', 'title for the project', 'Untitled')
.option('-d, --desc <description>', 'description for the project', 'No description.')
.option('-p, --path <path>', 'path to the markdown documentation files', 'docs')
.option('-a, --analytics <analytics>', 'code for your Google Analytics 4 property.')
.requiredOption('-b, --base <url>', 'base url for the relative links. For example: "apos-docs"')
.requiredOption('-r, --repo <url>', 'repo url for edit links. For example: "https://github.com/Apostolique/apos-docs/tree/main/"')
.parse();
Expand Down Expand Up @@ -43,5 +44,6 @@ fs.writeJsonSync('apos-docs/docs/_data/site.json', {
description: options.desc,
pathPrefix: options.base,
repo: options.repo,
docs: options.path
docs: options.path,
analytics: options.analytics
})
8 changes: 8 additions & 0 deletions src/_includes/default.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% if site.analytics %}
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.analytics }}"></script>
<script>
window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '{{ site.analytics }}');
</script>
{% endif %}

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/index.css">
Expand Down

0 comments on commit 4672674

Please sign in to comment.