Google Analytics(分析)GA4,用户可能被两倍计数?

发布于 2025-02-01 04:34:22 字数 1425 浏览 3 评论 0原文

我猜测Google Analytics(分析)中的转介指标在其中有一个ref(来自其他站点,例如 https://website.com?ref=facebook ) >参数从URL删除,是否会增加Direct度量?

仅仅想确保用户从昨天开始就不会被仔细计算,推荐直接公制是相同的,这很奇怪。如果是这样,是否有一种方法可以确保它们不被两倍计数?

使用GA4

GTAG.JS _APP.TSX

export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;

export const pageview = (url) => {
  window.gtag("config", GA_TRACKING_ID, {
    page_path: url,
  });
};

export const event = ({ action, category, label, value }) => {
  window.gtag("event", action, {
    event_category: category,
    event_label: label,
    value,
  });
};

在NextJS应用中

  const router = useRouter();
  useEffect(() => {
    const handleRouteChange = () => {
      gtag.pageview(window.location.href);
    };
    router.events.on("routeChangeComplete", handleRouteChange);
    router.events.on("hashChangeComplete", handleRouteChange);
    return () => {
      router.events.off("routeChangeComplete", handleRouteChange);
      router.events.off("hashChangeComplete", handleRouteChange);
    };
  }, [router.events]);

I'm guessing the Referral metric in Google Analytics increments when the url has a ref in it (coming from a different site such as https://website.com?ref=facebook), but if the user clicks on a separate page and the ref param is dropped from the url, does that increment the Direct metric?

Just want to make sure users aren't being double counted since just yesterday the Referral and Direct metric were the same which was odd. If that is the case, is there a way to make sure they are not double counted?

google analytics

Using ga4

gtag.js

export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID;

export const pageview = (url) => {
  window.gtag("config", GA_TRACKING_ID, {
    page_path: url,
  });
};

export const event = ({ action, category, label, value }) => {
  window.gtag("event", action, {
    event_category: category,
    event_label: label,
    value,
  });
};

_app.tsx in NextJS app

  const router = useRouter();
  useEffect(() => {
    const handleRouteChange = () => {
      gtag.pageview(window.location.href);
    };
    router.events.on("routeChangeComplete", handleRouteChange);
    router.events.on("hashChangeComplete", handleRouteChange);
    return () => {
      router.events.off("routeChangeComplete", handleRouteChange);
      router.events.off("hashChangeComplete", handleRouteChange);
    };
  }, [router.events]);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文