Code Monkey home page Code Monkey logo

volto-google-analytics's Introduction

volto-google-analytics

A widget for Volto to insert values for any language enabled

To be used with mrs-developer, see Volto docs for further usage informations.

Created with voltocli.

If using Volto < 16, use v1.3.0.

Usage

Add in your .env file of choice a variable:

RAZZLE_GA_CODE=UA-XXXXXXXX-X
#to use simple Universal Analytics (will be depracated in 2023)


RAZZLE_GA4_CODE=G-xxxxxxx
#to use Google Analytics 4f

and include useGoogleAnalytics in your project, like:

import { useGoogleAnalytics } from 'volto-google-analytics'

const Footer = () => {
  useGoogleAnalytics()

  return (
    ...
  )
}

GDPL

If your portal needs to follow GDPL, you can pass a parameter to the useGoogleAnalytics hook telling it whether or not we can create a cookie. If false is passed, GA will not be initialized, causing the cookie not to be created. The page view will also not be counted. If true is passed and GA has not been initialized, it will be initialized and the cookie will be written. If the parameter is not passed, true will be assumed. Example:

import { useGoogleAnalytics } from 'volto-google-analytics'

const Footer = ({cookieAllowed}) => {

  useGoogleAnalytics(cookieAllowed);

  return (
    ...
  )
}

Cookies expire

By default, Google Analytics cokkies expiration is set to 6 month. But you colud change the expiration period (expressing it in seconds), setting it from config:

config.settings['volto-google-analytics'].cookieExpires = 6 * 30 * 24 * 60 * 60; // in seconds. Default: 6 month

Universal Analytics and Google Analytics 4

Google will deprecate Universal Analytics on July 1, 2023, in favor of Google Analytics 4. Unitl that date, you could use Universal Analytics and Google Analytics 4 simultaneously, simply adding both RAZZLE_GA_CODE and RAZZLE_GA4_CODE in your .env.

volto-google-analytics's People

Contributors

giuliaghisini avatar nzambello avatar pnicolli avatar wesleybl avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

12-malak

volto-google-analytics's Issues

Just having the addon on a portal should not create cookies

If I have volto-google-analytics installed on a portal, cookies are created without even calling useGoogleAnalytics. For GDPL reasons, cookies should not be created in this situation, as we need to obtain the user's consent first.

Cookies are created when initializing GA. So I propose that this code stays inside a function, to be called explicitly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.