All Projects → andrezimpel → gatsby-plugin-gdpr-cookies

andrezimpel / gatsby-plugin-gdpr-cookies

Licence: Apache-2.0 license
Gatsby plugin to add Google Analytics (V4 is supported), Google Tag Manager, Facebook Pixel, TikTok Pixel and Hotjar in a GDPR form to your site.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to gatsby-plugin-gdpr-cookies

analytics-js-without-segment
A toolset to use Segments open-source analytics library (analytics.js) WITHOUT using the paid Segment service (segment.com). To be used with your favorite analytics-tools like Google Analytics, Mixpanel, Hotjar, etc.
Stars: ✭ 47 (-46.59%)
Mutual labels:  google-analytics, hotjar
scripts
Open Source Public Scripts for Simple Analytics
Stars: ✭ 62 (-29.55%)
Mutual labels:  google-analytics, analytics-tracking
gatsby-remark-embedded-codesandbox
A Gatsby Remark plugin for embedding Codesandbox given a folder of files
Stars: ✭ 31 (-64.77%)
Mutual labels:  gatsby-plugin
gtm-guidelines
A collection of best practices for your daily Google Tag Manager routine
Stars: ✭ 39 (-55.68%)
Mutual labels:  google-analytics
nextjs-google-analytics
Google Analytics for Next.js
Stars: ✭ 242 (+175%)
Mutual labels:  google-analytics
fusion
🚀 Open-source alternative for Mixpanel - Amplitude - Hotjar - Fullstory✨
Stars: ✭ 199 (+126.14%)
Mutual labels:  analytics-tracking
gatsby-remark-numbered-footnotes
A small plugin to change named footnotes to numbered footnotes in your Gatsby pages using Markdown.
Stars: ✭ 15 (-82.95%)
Mutual labels:  gatsby-plugin
Centcount Analytics
An open-source web analytics software. Developed by using PHP + MySQL + Redis, Can be easily deployed on your own server, 100% data ownership.
Stars: ✭ 249 (+182.95%)
Mutual labels:  google-analytics
php-analytics-event
Create a Google Analytics Event from PHP
Stars: ✭ 23 (-73.86%)
Mutual labels:  google-analytics
gatsby-pantry
Gatsby Plugin Pantry 🤤
Stars: ✭ 23 (-73.86%)
Mutual labels:  gatsby-plugin
tag-manager
Website analytics, JavaScript error tracking + analytics, tag manager, data ingest endpoint creation (tracking pixels). GDPR + CCPA compliant.
Stars: ✭ 279 (+217.05%)
Mutual labels:  google-analytics
angular-scaffolding
🔥 A seed project to help us get up & running with Progressive Web Apps, Google Analytics, Angular Universal, and be able to deploy to App Engine & GitHub Pages
Stars: ✭ 12 (-86.36%)
Mutual labels:  google-analytics
yii2-stat
Yii2 Multi Web Statistic Module (yametrika, google-analytic, own db-counter)
Stars: ✭ 18 (-79.55%)
Mutual labels:  google-analytics
social-post-api
Social Media API: Automate Posting and Analytics to Social Networks like Instagram, TikTok, Twitter, Facebook, LinkedIn, Reddit, YouTube, and Telegram
Stars: ✭ 38 (-56.82%)
Mutual labels:  tiktok
gatsby-remark-highlight-code
Adds stylish cards and syntax highlighting to code blocks in markdown files
Stars: ✭ 63 (-28.41%)
Mutual labels:  gatsby-plugin
gatsby-remark-design-system-example
Example page for "gatsby-remark-design-system"
Stars: ✭ 13 (-85.23%)
Mutual labels:  gatsby-plugin
gatsby-plugin-matomo
🥂 Gatsby plugin to add Matomo (formerly Piwik) onto a site.
Stars: ✭ 56 (-36.36%)
Mutual labels:  gatsby-plugin
gatsby-remark-relative-images
Convert markdown image src(s) to be relative for gatsby-remark-images.
Stars: ✭ 79 (-10.23%)
Mutual labels:  gatsby-plugin
vue-hotjar
A NPM package to easily integrate Hotjar to any Vue 2 Project
Stars: ✭ 26 (-70.45%)
Mutual labels:  hotjar
privera
Use the tools you know. Respect users' privacy. Forget cookie consents. Comply with GDPR, ePrivacy, COPPA, CalOPPA, PECR, PIPEDA, CASL; you name it.
Stars: ✭ 23 (-73.86%)
Mutual labels:  google-analytics

gatsby-plugin-gdpr-cookies

Gatsby plugin to add Google Analytics (V4 is supported), Google Tag Manager, Facebook Pixel, TikTok Pixel and Hotjar in a GDPR form to your site.

Version 2: I did rewrite the whole plugin to remove all the ssr that was done before. This will ensure that no data is ever sent before the cookies are set to true and the plugin has been initialized. There are no breaking changes. The configuration is exactly the same and and initializeAndTrack(location) does still work as before. I also removed some dependencies to keep the bundle size as small as possible.

Feedback is much appreciated 🖖🏽

Install

yarn add gatsby-plugin-gdpr-cookies or npm install --save gatsby-plugin-gdpr-cookies

How to use

// in your gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-gdpr-cookies`,
      options: {
        googleAnalytics: {
          trackingId: 'YOUR_GOOGLE_ANALYTICS_TRACKING_ID', // leave empty if you want to disable the tracker
          cookieName: 'gatsby-gdpr-google-analytics', // default
          anonymize: true, // default
          allowAdFeatures: false // default
        },
        googleTagManager: {
          trackingId: 'YOUR_GOOGLE_TAG_MANAGER_TRACKING_ID', // leave empty if you want to disable the tracker
          cookieName: 'gatsby-gdpr-google-tagmanager', // default
          dataLayerName: 'dataLayer', // default
        },
        facebookPixel: {
          pixelId: 'YOUR_FACEBOOK_PIXEL_ID', // leave empty if you want to disable the tracker
          cookieName: 'gatsby-gdpr-facebook-pixel', // default
        },
        tikTokPixel: {
          pixelId: 'YOUR_TIKTOK_PIXEL_ID', // leave empty if you want to disable the tracker
          cookieName: 'gatsby-gdpr-tiktok-pixel', // default
        },
        hotjar: {
          hjid: 'YOUR_HOTJAR_ID',
          hjsv: 'YOUR_HOTJAR_SNIPPET_VERSION',
          cookieName: 'gatsby-gdpr-hotjar', // default
        },
        linkedin: {
          trackingId: 'YOUR_LINKEDIN_TRACKING_ID', // leave empty if you want to disable the tracker
          cookieName: 'gatsby-gdpr-linked-in', // default
        },
        // defines the environments where the tracking should be available  - default is ["production"]
        environments: ['production', 'development']
      },
    },
  ],
}

How it works

First of all the plugin checks in which environment your site is running. If it's currently running in one of your defined environments it will add the tracking code by default to the <head>/<body> of your site. It will not be activated or initialized by this.

By default this plugin will not send any data to Google or Facebook to make it GDPR compliant. The user first needs to accept your cookie policy. By accepting that you need to set cookies for the tracker you want to use - gatsby-gdpr-google-analytics, gatsby-gdpr-google-tagmanager, gatsby-gdpr-facebook-pixel. Depending on the user input the value of each of the cookies should be true or false.

If the gatsby-gdpr-google-analytics cookie is set to true, Google Analytics will be initialized onClientEntry. Same is for the Google Tag Manager and Facebook Pixel. The plugin will check if cookies for Google Analytics or Facebook Pixel have been set between route changes on onRouteUpdate. Reloading the page after setting the cookies is not required anymore.

The page view will be tracked on onRouteUpdate.

Important: read below about using the plugin with Google Tag Manager.

Options

Google Analytics

trackingId

Here you place your Google Analytics tracking ID. Analytics 4 is supported by the plugin beginning with v1.0.12.

cookieName

You can use a custom cookie name if you need to!

allowAdFeatures

The default value is false.

anonymize

Some countries (such as Germany) require you to use the _anonymizeIP function for Google Analytics. Otherwise you are not allowed to use it. The option adds two blocks to the code:

ga('set', 'anonymizeIp', 1);

opt-out

Your visitors should be able to opt-out for analytics tracking. By setting the Google Analytics cookie to false tracking will be stopped. Alternatively you can also set the corresponding window variable to false:

window[`ga-disable-YOUR_TRACKING_ID_HERE`] = true

Google Tag Manager

trackingId

Here you place your Google Tag Manager tracking ID.

cookieName

You can use a custom cookie name if you need to!

dataLayerName

Data layer name

routeChangeEvent

The name of the event which will be triggered when route changes Defaults to gatsbyRouteChange

gtmAuth

Google Tag Manager environment auth string

gtmPreview

Google Tag Manager environment preview name

defaultDataLayer

Data layer to be set before GTM is loaded. Should be an object or a function that is executed in the browser, e.g.:

  defaultDataLayer: { platform: "gatsby" }
  defaultDataLayer: function() {
    return {
      pageType: window.pageType,
    }
  }

Tracking routes

Out of the box this plugin will simply load Google Tag Manager on the initial page/app load. It’s up to you to fire tags based on changes in your app.

This plugin will fire a new event called gatsbyRouteChange (by default) on Gatsby's onRouteUpdate (only if the consent was given by a visitor). To record this in Google Tag Manager, we will need to add a trigger to the desired tag to listen for the event:

In order to do that, go to Tags. Under Triggering click the pencil icon, then the ”+” button to add a new trigger. In the Choose a trigger window, click on the ”+” button again. Choose the trigger type by clicking the pencil button and clicking Custom event. For event name, enter gatsbyRouteChange. This tag will now catch every route change in Gatsby, and you can add Google tag services as you wish to it.

Facebook Pixel

pixelId

Here you place your Facebook Pixel ID.

cookieName

You can use a custom cookie name if you need to!

TikTok Pixel

pixelId

Here you place your TikTok Pixel ID.

cookieName

You can use a custom cookie name if you need to!

Hotjar

hjid

Stands for 'Hotjar ID' - Your site's ID. This is the ID which tells Hotjar which site settings it should load and where it should save the data collected.

hjsv

Stands for 'Hotjar Snippet Version' - The version of the Tracking Code you are using. This is only needed if Hotjar ever updates the Tracking Code and needs to discontinue older ones. Knowing which version your site includes allows hotjar team to contact you and inform you accordingly.

cookieName

You can use a custom cookie name if you need to!

Chatwoot

Chatwoot is an open source customer engagement platform. This plugin manages installing and initializing Chatwoot if the respective cookie is true.

baseUrl

You can find the base url within your inbox.

websiteToken

You can find the website token within your inbox.

cookieName

You can use a custom cookie name if you need to!

LinkedIn

trackingId

Here you place your LinkedIn tracking ID.

cookieName

You can use a custom cookie name if you need to!

Initialize and track

This gatsby plugin now supports initializing and tracking right after a user accepts the cookie consent.

// in your cookie banner
import { useLocation } from "@reach/router" // this helps tracking the location
import { initializeAndTrack } from 'gatsby-plugin-gdpr-cookies'

Then you can execute initializeAndTrack(location) in your cookie banner callback. This will initialize the plugin with your options from the gatsby-config.js and then starts tracking the user based on the cookies/services are accepted.

// in your cookie banner
const location = useLocation()
initializeAndTrack(location)

Contributors

Thanks goes to these wonderful people who helped shaping this project.

Simon Vanherweghe

Stefan Tertan

Osvaldas Valutis

Théo

Paul Brickles

Ferran Buireu

Daniel Spaude

Hahlh B

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].