Coder Social home page Coder Social logo

Comments (4)

tfcb93 avatar tfcb93 commented on April 28, 2024 1

Oh yeah! I kinda did a turnaround using the ReactGA library. I register Analytics using it and later use ReactGA.ga('set', 'exp', cookie); to register the cookie set-up by the middleware.

I also did not use the script below since I was having problems getting 2 experience IDs and this can discard your experience (kinda following https://developers.google.com/optimize/devguides/experiments?technology=ga4#implement-experiment).

<Script
        src={`https://www.googleoptimize.com/optimize.js?id=${process.env.NEXT_PUBLIC_OPTIMIZE_CONTAINER_ID}`}
/>

It'll not recognize the Optimize installation, but seems it's not obligatory (like the server-side experiment, it's not necessary as well).
I hope you get the idea and go through it 🙏 And sorry for not updating the thread with this answer. If you need something else just post and I'll try my best to help you when I can o/

from examples.

DopamineDriven avatar DopamineDriven commented on April 28, 2024 1

I do this in my repos for dealing with the datalayer. Make a Root index.d.ts, set declaration: true in the tsconfig, and --

/// <reference types="google.maps" />
/// <reference types="gtag.js" />

declare module "google.maps";
declare module "gtag.js";

interface Window {
  dataLayer?: object[];
}

now, the dataLayer will be recognized and by declaring the google.maps and gtag.js modules all of their typedefs are available for consumption globally with full Intellisense, no imports required (I only have the @types/* version of either installed)


  • example of the gtag types being consumed with intellisense
    image

  • example using the globally available gtag typedefs in _app.tsx

// real-time GA4 reporting
export function reportGAVitals({
  id,
  name,
  label,
  startTime,
  value
}: NextWebVitalsMetric) {
  if (typeof window !== "undefined")
    window.gtag("event", name, {
      event_category:
        label === "web-vital" ? "Web Vitals" : "Next.js custom metric",
      value: Math.round(name === "CLS" ? value * 1000 : value), // values must be integers
      event_label: id, // id unique to current page load
      non_interaction: true // avoids affecting bounce rate.
    });
}

from examples.

rnatto-gempe avatar rnatto-gempe commented on April 28, 2024

any solution here?

from examples.

lfades avatar lfades commented on April 28, 2024

Our Google Optimize example might disappear in the future as the service will sunset this year, closing the issue for now.

from examples.

Related Issues (20)

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.