Next13(应用目录)+ Google标签管理器 + Google Analytics(标签未触发)

huangapple go评论72阅读模式
英文:

Next13 (App Directory) + Google Tag Manager + Google Analytics (Tags Not Firing)

问题

Struggling with integrating Google Tag Manager + Google Analytics Tag with Next 13 (App Directory). Not sure whether the problem is more with Next13 or with my Tag Manager setup (though there is not so much to set up, actually)

我在尝试将Google Tag Manager和Google Analytics标签集成到Next 13(应用目录)中遇到困难。不确定问题是与Next 13还是我的Tag Manager设置更相关(尽管实际上没有太多需要设置的内容)。

I have been following this tutorial. With this, am I supposed to activiate History Change Triggers in Google Tag Manager?

我一直在按照这个教程进行操作。根据这个教程,我是否应该在Google Tag Manager中启用历史更改触发器?

When I do send events via

当我通过以下方式发送事件时

    event: 'pageview',
    page: url,
  })

I do see a pageview event in my Google Tag Manager Preview, but my Google Analytics Tag isn't fired, even though I have it set to trigger on "All Pages". Any ideas?

我在Google Tag Manager预览中确实看到了pageview事件,但是我的Google Analytics标签没有触发,尽管我已经将其设置为在“所有页面”上触发。有任何想法吗?

英文:

Struggling with integrating Google Tag Manager + Google Analytics Tag with Next 13 (App Directory). Not sure whether the problem is more with Next13 or with my Tag Manager setup (though there is not so much to set up, actually)

I have been following this tutorial. With this, am I supposed to activiate History Change Triggers in Google Tag Manager?

When I do send events via

  window.dataLayer.push({
    event: 'pageview',
    page: url,
  })

I do see a pageview event in my Google Tag Manager Preview, but my Google Analytics Tag isn't fired, even though I have it set to trigger on "All Pages". Any ideas?

答案1

得分: 1

"use client";
import Head from "next/head";
import Script from "next/script";
import React from "react";

const GoogleTag = () => {
  return (
    <div>
      <Head>
        <meta
          name="google-site-verification"
          content="1jRUAxx6jZc-abqxxoa-rtI-6prcxxznoxxEKC6xxESTjxxq89FcIbg"
        />
      </Head>
      <Script
        async
        src="https://www.googletagmanager.com/gtag/js?id=xxxxxxxx"
        strategy="lazyOnload"
      />
      <Script
        id="google"
        dangerouslySetInnerHTML={{
          __html: ` window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());

            gtag('config', 'xxxxxxxx');`,
        }}
      />
    </div>
  );
};

export default GoogleTag;
英文:

I create components and use them in the main layout :

"use client";
import Head from "next/head";
import Script from "next/script";
import React from "react";

const GoogleTag = () => {
  return (
    <div>
      <Head>
        <meta
          name="google-site-verification"
          content="1jRUAxx6jZc-abqxxoa-rtI-6prcxxznoxxEKC6xxESTjxxq89FcIbg"
        />
      </Head>
      <Script
        async
        src="https://www.googletagmanager.com/gtag/js?id=xxxxxxxx"
        strategy="lazyOnload"
      />
      <Script
        id="google"
        dangerouslySetInnerHTML={{
          __html: ` window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
    
            gtag('config', 'xxxxxxxx');`,
        }}
      />
    </div>
  );
};

export default GoogleTag;

huangapple
  • 本文由 发表于 2023年6月13日 18:36:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76464019.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定