diff --git a/.env.sample b/.env.sample index 455c5fea..ee29d750 100644 --- a/.env.sample +++ b/.env.sample @@ -1,4 +1,6 @@ -GATSBY_GITHUB_TOKEN=your_token +GITHUB_TOKEN=your_token GATSBY_MAPBOX_ACCESS_TOKEN= GATSBY_TYPEKIT_ID=xxx -INFURA_ID=xxx \ No newline at end of file +GATSBY_UMAMI_SCRIPT_URL=xxx +GATSBY_UMAMI_WEBSITE_ID=xxx +GATSBY_INFURA_ID=xxx \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e3310d3..cbeef06a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,6 +44,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GATSBY_TYPEKIT_ID: ${{ secrets.GATSBY_TYPEKIT_ID }} GATSBY_MAPBOX_ACCESS_TOKEN: ${{ secrets.GATSBY_MAPBOX_ACCESS_TOKEN }} + GATSBY_UMAMI_SCRIPT_URL: ${{ secrets.GATSBY_UMAMI_SCRIPT_URL }} + GATSBY_UMAMI_WEBSITE_ID: ${{ secrets.GATSBY_UMAMI_WEBSITE_ID }} + GATSBY_INFURA_ID: ${{ secrets.GATSBY_INFURA_ID }} - run: npm test - uses: actions/upload-artifact@v3 diff --git a/README.md b/README.md index cf49cf66..ff3285fa 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ - [📝 GitHub changelog rendering](#-github-changelog-rendering) - [🌗 Theme Switcher](#-theme-switcher) - [🏆 SEO component](#-seo-component) - - [📈 Matomo (formerly Piwik) analytics tracking](#-matomo-formerly-piwik-analytics-tracking) - [gatsby-redirect-from](#gatsby-redirect-from) - [💎 Importing SVG assets](#-importing-svg-assets) - [🍬 Typekit component](#-typekit-component) @@ -134,12 +133,6 @@ If you want to know how this works, have a look at the respective component unde - [`src/components/atoms/SEO.jsx`](src/components/atoms/SEO.jsx) -### 📈 Matomo (formerly Piwik) analytics tracking - -Site sends usage statistics to my own [Matomo](https://matomo.org) installation. To make this work in Gatsby, I created and open sourced a plugin which is in use on this site. - -- [gatsby-plugin-matomo](https://github.com/kremalicious/gatsby-plugin-matomo) - ### gatsby-redirect-from - [gatsby-redirect-from](https://github.com/kremalicious/gatsby-redirect-from) diff --git a/gatsby-config.ts b/gatsby-config.ts index dba9fc7c..f063883f 100644 --- a/gatsby-config.ts +++ b/gatsby-config.ts @@ -135,15 +135,6 @@ const config: GatsbyConfig = { } } }, - { - resolve: 'gatsby-plugin-matomo', - options: { - siteId: '1', - matomoUrl: 'https://analytics.kremalicious.com', - siteUrl: `${siteConfig.siteUrl}`, - trackLoad: false - } - }, { resolve: 'gatsby-plugin-manifest', options: { diff --git a/gatsby-ssr.tsx b/gatsby-ssr.tsx index 11650382..79043c3b 100644 --- a/gatsby-ssr.tsx +++ b/gatsby-ssr.tsx @@ -1,5 +1,24 @@ +import React from 'react' import { GatsbySSR } from 'gatsby' import wrapPageElementWithLayout from './src/helpers/wrapPageElement' +import { UMAMI_SCRIPT_URL, UMAMI_WEBSITE_ID } from './src/helpers/umami' export const wrapPageElement: GatsbySSR['wrapPageElement'] = wrapPageElementWithLayout + +export const onRenderBody = ({ setPostBodyComponents }) => { + const isEnabled = process.env.NODE_ENV === 'production' + + if (!isEnabled) { + return null + } + + const options = { + src: UMAMI_SCRIPT_URL, + 'data-website-id': UMAMI_WEBSITE_ID + } + + return setPostBodyComponents([ +