Google 具有多个联系表单的分析 7 转化跟踪问题
Google analytics with multiple contact forms 7 conversion tracking problem
我在 google 分析中创建多个转换时遇到问题,而无需在同一站点上使用具有多个表单的标签管理器,使用 wordpress 的 Contact form 7 插件
.
在网站的 header 中,我添加了如下代码:
document.addEventListener( 'wpcf7mailsent', function( event ) {
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f712-o2'
});
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f1399-o1'
});
} );
<script>
wpcf7-f712-o2 和 wpcf7-f1399-o1 是 DIV 中的 ID,由 html:
中的联系表 7 创建
<div role="form" class="wpcf7" id="wpcf7-f712-o2" lang="pl-PL" dir="ltr">
<div class="screen-reader-response"><p role="status" aria-live="polite" aria-atomic="true"></p> <ul></ul></div>
<form action="/#wpcf7-f712-o2" method="post" class="wpcf7-form init" novalidate="novalidate" data-status="init">
....
并且在 google 分析转换中我设置了两个转换:
类别:Contact_form
操作:提交
标签:wpcf7-f712-o2
和
类别:Contact_form
操作:提交
标签:wpcf7-f1399-o1
问题是,如果我测试其中一种形式,google 分析会向我提供转换有效但来自两种形式的信息。虽然它应该只适用于一个所需的转换,但不能同时适用于两者。
是否可以在不使用 TAG 管理器的情况下进行设置?
在代码的第一行中,您为任何名为 'wpcf7mailsent'
的事件创建了一个侦听器。因此,当触发此事件时,将执行具有两个 ga()
调用的回调。这意味着,无论您是通过单击一个按钮还是另一个按钮来触发 'wpcf7mailsent'
事件,都会执行同时触发 ga()
的回调,从而将两次转换发送到 Google Analytics。
如果您使用 Google 标签管理器,我建议创建两个标签,每个表单一个。确保附加到每个标签的触发器对应于它自己的形式,而不是另一个。要区分单击了哪个按钮,您可以使用按钮的文本或 class 名称。
如果您不想使用 Google 跟踪代码管理器,只需确保在回调中触发正确的 ga()
调用即可。与在跟踪代码管理器中一样,您应该能够从单击的按钮中检索 ID、class 名称或其他任何内容,以便区分已提交的表单。
我在以下位置找到了解决方案:https://agvento.by/en/web-development-en/how-to-create-and-edit-goals-in-google-analytics-for-contact-form-7/
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ('712' == event.detail.contactFormId){
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f712-o2'
});
}
if ('1399' == event.detail.contactFormId){
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f1399-o1'
});
}
});
</script>
我从一个联系表单发送了提交,google 分析注册了一个发送的表单转换。
我在 google 分析中创建多个转换时遇到问题,而无需在同一站点上使用具有多个表单的标签管理器,使用 wordpress 的 Contact form 7 插件 . 在网站的 header 中,我添加了如下代码:
document.addEventListener( 'wpcf7mailsent', function( event ) {
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f712-o2'
});
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f1399-o1'
});
} );
<script>
wpcf7-f712-o2 和 wpcf7-f1399-o1 是 DIV 中的 ID,由 html:
中的联系表 7 创建<div role="form" class="wpcf7" id="wpcf7-f712-o2" lang="pl-PL" dir="ltr">
<div class="screen-reader-response"><p role="status" aria-live="polite" aria-atomic="true"></p> <ul></ul></div>
<form action="/#wpcf7-f712-o2" method="post" class="wpcf7-form init" novalidate="novalidate" data-status="init">
....
并且在 google 分析转换中我设置了两个转换:
类别:Contact_form
操作:提交
标签:wpcf7-f712-o2
和
类别:Contact_form
操作:提交
标签:wpcf7-f1399-o1
问题是,如果我测试其中一种形式,google 分析会向我提供转换有效但来自两种形式的信息。虽然它应该只适用于一个所需的转换,但不能同时适用于两者。
是否可以在不使用 TAG 管理器的情况下进行设置?
在代码的第一行中,您为任何名为 'wpcf7mailsent'
的事件创建了一个侦听器。因此,当触发此事件时,将执行具有两个 ga()
调用的回调。这意味着,无论您是通过单击一个按钮还是另一个按钮来触发 'wpcf7mailsent'
事件,都会执行同时触发 ga()
的回调,从而将两次转换发送到 Google Analytics。
如果您使用 Google 标签管理器,我建议创建两个标签,每个表单一个。确保附加到每个标签的触发器对应于它自己的形式,而不是另一个。要区分单击了哪个按钮,您可以使用按钮的文本或 class 名称。
如果您不想使用 Google 跟踪代码管理器,只需确保在回调中触发正确的 ga()
调用即可。与在跟踪代码管理器中一样,您应该能够从单击的按钮中检索 ID、class 名称或其他任何内容,以便区分已提交的表单。
我在以下位置找到了解决方案:https://agvento.by/en/web-development-en/how-to-create-and-edit-goals-in-google-analytics-for-contact-form-7/
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ('712' == event.detail.contactFormId){
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f712-o2'
});
}
if ('1399' == event.detail.contactFormId){
ga('send', {
hitType: 'event',
eventCategory: 'contact_form',
eventAction: 'submit',
eventLabel: 'wpcf7-f1399-o1'
});
}
});
</script>
我从一个联系表单发送了提交,google 分析注册了一个发送的表单转换。