/
githubmirror
/
puppeteer
Обзор
Документация
Войти
/
githubmirror
/
puppeteer
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
website/src/theme/Root.js
53 строки
1 KB
Matthias Rohmer
docs: add Google Analytics with consent banner to pptr.dev (#12496)
06 авг 2024, 13:49
Не верифицирован
06 авг 2024, 13:49
154f64d
Код
Авторство
О чём код?
/** * @license * Copyright 2024 Google Inc. * SPDX-License-Identifier: Apache-2.0 */ import React, {useEffect} from 'react'; import CookieConsent, {getCookieConsentValue} from 'react-cookie-consent'; function enableGoogleAnalytics() { const hasConsent = getCookieConsentValue(); if (!hasConsent) { return; } window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'G-J15CTWBVHX', {anonymize_ip: true}); } export default function Root({children}) { useEffect(enableGoogleAnalytics, []); return ( <> {children} <CookieConsent location="bottom" buttonText="Okay, got it!" disableButtonStyles={true} buttonWrapperClasses="padding--sm" buttonClasses="button button--primary button--outline" contentStyle={{ fontSize: 'inherit', }} style={{ color: 'var(--ifm-color-primary-contrast-foreground)', background: 'var(--ifm-color-primary-contrast-background)', }} onAccept={enableGoogleAnalytics} > pptr.dev, Puppeteer's documentation site, uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.{' '} <a href="https://policies.google.com/technologies/cookies"> Learn more. </a> </CookieConsent> </> ); }