diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 980dc99..1b0ef78 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -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: @@ -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 diff --git a/index.js b/index.js index ecc9137..3468097 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ program .option('-t, --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(); @@ -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 }) diff --git a/src/_includes/default.njk b/src/_includes/default.njk index 0d0bd60..c9e16eb 100644 --- a/src/_includes/default.njk +++ b/src/_includes/default.njk @@ -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">