Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/components/analytics.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { join } from "path";6import basePath from "lib/base-path";7import useCustomize from "lib/use-customize";89function GoogleAnalytics() {10const { googleAnalytics } = useCustomize();1112const GA4_TRACKING_ID = googleAnalytics;13if (!GA4_TRACKING_ID) return [];14const ga = `\15window.dataLayer = window.dataLayer || [];16function gtag(){dataLayer.push(arguments);}17gtag('js', new Date());18gtag('config', '${GA4_TRACKING_ID}');\19`;20return [21<script22key={"google-analytics-0"}23async={true}24defer={true}25src={`https://www.googletagmanager.com/gtag/js?id=${GA4_TRACKING_ID}`}26/>,27<script28key={"google-analytics-1"}29dangerouslySetInnerHTML={{ __html: ga }}30/>,31];32}3334function CoCalcAnalytics() {35return [36<script37key="cocalc-analytics"38async={true}39defer={true}40src={join(basePath, "analytics.js")}41/>,42];43}4445// Why so careful not to nest things? See46// https://nextjs.org/docs/api-reference/next/head47// NOTE: Analytics can't be in Head because of script tags! https://github.com/vercel/next.js/pull/2625348export default function Analytics(): JSX.Element {49return <>{GoogleAnalytics().concat(CoCalcAnalytics())}</>;50}515253