本文将带您了解关于将gtag脚本添加到外部JavaScript文件的新内容,同时我们还将为您解释gtr脚本执行流程的相关知识,另外,我们还将为您提供关于@types/gtag.js错误:“config
本文将带您了解关于将 gtag 脚本添加到外部 JavaScript 文件的新内容,同时我们还将为您解释gtr脚本执行流程的相关知识,另外,我们还将为您提供关于@types/gtag.js 错误:“config”类型的参数不能分配给“consent”类型的参数、Adobe 发布:GTAG 活动view_item 等、Angular 无法识别 index.html 中的 Google gtag、Google Ads gtag 跟踪代码不起作用,但 analytics.js 在同一页面上运行的实用信息。
本文目录一览:- 将 gtag 脚本添加到外部 JavaScript 文件(gtr脚本执行流程)
- @types/gtag.js 错误:“config”类型的参数不能分配给“consent”类型的参数
- Adobe 发布:GTAG 活动view_item 等
- Angular 无法识别 index.html 中的 Google gtag
- Google Ads gtag 跟踪代码不起作用,但 analytics.js 在同一页面上运行
将 gtag 脚本添加到外部 JavaScript 文件(gtr脚本执行流程)
如何解决将 gtag 脚本添加到外部 JavaScript 文件
我已将以下代码添加到我的网页以将事件信息发送到 Google Analytics:
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-144340016-1"></script>
<!-- Google Analytics -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag(''js'',new Date());
gtag(''config'',''UA-144340016-1'');
</script>
<!-- End Google Analytics -->
</head>
<body>
<a id=''lin1'' href="cool.com" onclick="gtag(''event'',''click'',{''event_category'': ''cat1'',''event_label'': ''lab1''});">
</a>
</body
现在我不想在 html 上使用内联 onclick
事件,我想把这个位移动到一个单独的 JavaScript 代码,所以像这样:
my.js
$(''#lin1'').click(function() {
gtag(''event'',''event_label'': ''lab1''});
});
然后在我的网页底部添加 my.js。这种方法有什么问题吗?我看到的所有文档都将 gtag
事件直接添加到 HTML 中,这就是为什么我想确保我正在做的事情是否没有缺点
解决方法
具有将点击发送到 Analytics 的函数的函数库没有问题。最终,文档建议将代码段 (gtag.js
) 直接插入 HTML 的 head
中(但这看起来您已经这样做了)。
@types/gtag.js 错误:“config”类型的参数不能分配给“consent”类型的参数
如何解决@types/gtag.js 错误:“config”类型的参数不能分配给“consent”类型的参数
我正在尝试将 Google Analytics 添加到 Next.js 站点。我正在遵循 JavaScript 中的 this 指南,但我的应用程序是 TypeScript。安装@types/gtag.js 后,出现此错误:
No overload matches this call.
The last overload gave the following error.
Argument of type ''"config"'' is not assignable to parameter of type ''"consent"''.ts(2769)
index.d.ts(19,5): The last overload is declared here.
在我的这一行代码中:
window.gtag(''config'',process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS,{
page_path: url,})
这里是类型定义:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/gtag.js/index.d.ts
我不确定类型是否不正确,但代码大概可以工作,因为它直接来自教程。
我的临时解决方法是声明 gtag: any
:
declare global {
interface Window {
gtag: any
}
}
解决方法
我遇到了这个错误,我通过将 string
类型添加到 NEXT_PUBLIC_GOOGLE_ANALYTICS
来解决这个问题(在你的情况下)。就我而言,因为 process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS
的类型是 string | undefined
。
Adobe 发布:GTAG 活动view_item 等
如何解决Adobe 发布:GTAG 活动view_item 等
我在 Adobe Launch(自定义代码标签类型)中为 Google Ads 设置 gtag ecom 事件。 基本上,我将事件数据添加到 dataLayer (gtag(''event''...)) 并且没有任何反应,至少在网络选项卡中,但是我确定必须有发送事件数据的请求。
在使用 Adobe Launch 之前,我从未这样做过。 在增强型经济事件的 GTM 中,您必须添加带有触发器的标签。所以我认为由于事件数据确实被添加到 dataLayer,我必须弄清楚如何“手动”发送这些数据(没有 gtm)。
gtag(''js'',new Date());
gtag(''config'',''AW-XXXXXXX'');
gtag(''event'',conf[''type''],{
''value'': conf[''price''],''items'': [
{
''id'': conf[''products''],''google_business_vertical'': ''retail''
}]
});
数据被添加到 dataLayer 就好了:
dataLayer screenshot
有什么想法吗?
Angular 无法识别 index.html 中的 Google gtag
如何解决Angular 无法识别 index.html 中的 Google gtag
按照 google 的指示,在 head 部分的 index.html
中添加了 gtag。但是,我遇到了错误。
<!doctype html>
<html lang="en">
<head>
<base href="/">
<Meta charset="utf-8">
<Meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<title>Hello</title>
<!-- Favicon -->
<link href="./assets/img/favicon.ico" rel="icon" type="image/png">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
<!-- Google Tag Manager -->
<script>(function (w,d,s,l,i) {
w[l] = w[l] || []; w[l].push({
''gtm.start'':
new Date().getTime(),event: ''gtm.js''
}); var f = d.getElementsByTagName(s)[0],j = d.createElement(s),dl = l != ''dataLayer'' ? ''&l='' + l : ''''; j.async = true; j.src =
''https://www.googletagmanager.com/gtm.js?id='' + i + dl; f.parentNode.insertBefore(j,f);
})(window,document,''script'',''dataLayer'',''GTM-01jd9k'');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<app-root></app-root>
</body>
</html>
看控制台,
(索引):30 GET https://www.googletagmanager.com/gtm.js?id=GT....。净::ERR_ABORTED 404
似乎无法识别 insertBefore()
。
Failed to load resource: the server responded with a status of 404 ()
angular 如何识别 index.html 中的 gtag?任何帮助表示赞赏!
解决方法
使用 angular-google-tag-manager 谷歌标签管理器的 npm 包。我已经用过了。这是一个很棒的包。
Google Ads gtag 跟踪代码不起作用,但 analytics.js 在同一页面上运行
如何解决Google Ads gtag 跟踪代码不起作用,但 analytics.js 在同一页面上运行
请参阅此最小示例
我有一个像这样的静态 HTML 页面
<!DOCTYPE html>
<html>
<head>
<Meta charset="UTF-8" />
<Meta name="viewport" content="width=device-width,initial-scale=1.0" />
<Meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>New User</title>
</head>
<body>
<!-- Google Analytics Code -->
<script>
(function (i,s,o,g,r,a,m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function () {
(i[r].q = i[r].q || []).push(arguments);
}),(i[r].l = 1 * new Date());
(a = s.createElement(o)),(m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a,m);
})(
window,document,"script","https://www.google-analytics.com/analytics.js","ga"
);
ga("create","MY_UA","auto");
ga("send","pageview");
ga("send",{
hitType: "event",eventCategory: "livechatNewUser",eventAction: "redirect",});
</script>
<!-- Global site tag (gtag.js) -->
<script src="https://www.googletagmanager.com/gtag/js?id=MY_AdWords"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js",new Date());
gtag("config","MY_AdWords");
gtag("event","conversion",{
send_to: "MY_AdWords/MY_Label",});
</script>
<script language="javascript">
setTimeout(function () {
document.location.href = "/dashboard";
},1000);
</script>
</body>
</html>
3 天后,我的 ga 后端正在接收一些数据
但是,我的广告词后端没有收到任何数据
日期范围相同,为什么会这样?
解决方法
您使用的是 Google Analytics analytics.js 实现,而不是 gtag 实现。不过,这很好,您使用 gtag 方法调用 AdWords 转化事件。但是没有 gtag。
请看这里:https://support.google.com/google-ads/answer/6331314?hl=en#zippy=%2Cset-up-conversion-tracking-using-javascript%2Cset-up-conversion-tracking-using-the-global-site-tag
我建议将您的分析实现切换为 GA 的 gtag 实现,以便您可以同时使用两者。
今天关于将 gtag 脚本添加到外部 JavaScript 文件和gtr脚本执行流程的讲解已经结束,谢谢您的阅读,如果想了解更多关于@types/gtag.js 错误:“config”类型的参数不能分配给“consent”类型的参数、Adobe 发布:GTAG 活动view_item 等、Angular 无法识别 index.html 中的 Google gtag、Google Ads gtag 跟踪代码不起作用,但 analytics.js 在同一页面上运行的相关知识,请在本站搜索。
本文标签: