Google ajax 表单提交的分析目标未达到目标
Google Analytics Goal for ajax form submissions not scoring the goals
我试过这个答案,但它不能正常工作:
这个答案可能需要针对更新版本的 GA 进行更新。当通过 ajax.
提交页面时,我做了以下设置目标
$.ajax({
type: "POST",
url: "/some/page/that/does/not/have/ga/on/it.php",
data: { formData:formData },
success: function() {
// Some success message to user.
// Create a virtual page view that you can track in GA.
ga('send', {
'hitType' : 'pageview',
'page' : '/contact-us-success' // Virtual page (aka, does not actually exist) that you can now track in GA Goals as a destination page.
});
}
});
然后在 GA -> 管理 -> 目标 -> 新目标
(1) 目标设置 - 自定义
(2)目标描述->选择'Destination'。
(3) 目标详情 -> Destination 等于 /contact-us-success
希望这对其他人有帮助。
这是我当前的代码:
$(document).ready(function() {
// Antes de enviar
$('#formdata').submit(function() {
$('#botonenviar').hide();
$('#loader').show();
// Enviamos el formulario usando AJAX
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
// Mostramos un mensaje segun respuesta de PHP
success: function(rsp) {
if(rsp=='error')
$('#fracaso').show(),
$('#loader').hide()
;
else
$('#exito').show(),
$('#loader').hide(),
ga('send', {
'hitType' : 'pageview',
'page' : '/contact-us-success' // Virtual page (aka, does not actually exist) that you can now track in GA Goals as a destination page.
});
}
})
return false;
});
})
没有控制台错误,我什至禁用了广告拦截器。
由于您提到了 ga
对象:
ga('send','event', <Category>, <Action>, <Label>);
编辑:您使用标签管理器,因此您必须使用 dataLayer 对象。
这是跟踪联系表单的正确语法,然后您在 Analytics 中创建目标
$(document).ready(function() {
// Antes de enviar
$('#formdata').submit(function() {
$('#botonenviar').hide();
$('#loader').show();
// Enviamos el formulario usando AJAX
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
// Mostramos un mensaje segun respuesta de PHP
success: function(rsp) {
if(rsp=='error')
$('#fracaso').show(),
$('#loader').hide();
else
//ga('send','event','form','submitted');
dataLayer = dataLayer || []; // Safe init
dataLayer.push({'event' : 'form_submitted'});
$('#exito').show(),
$('#loader').hide(),
}
})
进入标签管理器,使用以下内容创建一个新标签:
代码配置 - Universal Analytics - 事件。
Event Category 和Event Action 你可以放你喜欢的,只要和你在Goal 信息中放的一样。请记住还要将 Google Analytics 属性 ID 设置为 Google Analytics 变量。
触发器配置 - 自定义事件,所有自定义事件,您将 form_submitted
放入文本框。
然后,如果需要,您可以创建一个 Event Goal 。您从 Real time > Events
测试它们并通过 Behaviour > Events
.
分析它们
我试过这个答案,但它不能正常工作:
这个答案可能需要针对更新版本的 GA 进行更新。当通过 ajax.
提交页面时,我做了以下设置目标$.ajax({
type: "POST",
url: "/some/page/that/does/not/have/ga/on/it.php",
data: { formData:formData },
success: function() {
// Some success message to user.
// Create a virtual page view that you can track in GA.
ga('send', {
'hitType' : 'pageview',
'page' : '/contact-us-success' // Virtual page (aka, does not actually exist) that you can now track in GA Goals as a destination page.
});
}
});
然后在 GA -> 管理 -> 目标 -> 新目标
(1) 目标设置 - 自定义 (2)目标描述->选择'Destination'。 (3) 目标详情 -> Destination 等于 /contact-us-success
希望这对其他人有帮助。
这是我当前的代码:
$(document).ready(function() {
// Antes de enviar
$('#formdata').submit(function() {
$('#botonenviar').hide();
$('#loader').show();
// Enviamos el formulario usando AJAX
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
// Mostramos un mensaje segun respuesta de PHP
success: function(rsp) {
if(rsp=='error')
$('#fracaso').show(),
$('#loader').hide()
;
else
$('#exito').show(),
$('#loader').hide(),
ga('send', {
'hitType' : 'pageview',
'page' : '/contact-us-success' // Virtual page (aka, does not actually exist) that you can now track in GA Goals as a destination page.
});
}
})
return false;
});
})
没有控制台错误,我什至禁用了广告拦截器。
由于您提到了 ga
对象:
ga('send','event', <Category>, <Action>, <Label>);
编辑:您使用标签管理器,因此您必须使用 dataLayer 对象。
这是跟踪联系表单的正确语法,然后您在 Analytics 中创建目标
$(document).ready(function() {
// Antes de enviar
$('#formdata').submit(function() {
$('#botonenviar').hide();
$('#loader').show();
// Enviamos el formulario usando AJAX
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
// Mostramos un mensaje segun respuesta de PHP
success: function(rsp) {
if(rsp=='error')
$('#fracaso').show(),
$('#loader').hide();
else
//ga('send','event','form','submitted');
dataLayer = dataLayer || []; // Safe init
dataLayer.push({'event' : 'form_submitted'});
$('#exito').show(),
$('#loader').hide(),
}
})
进入标签管理器,使用以下内容创建一个新标签:
代码配置 - Universal Analytics - 事件。
Event Category 和Event Action 你可以放你喜欢的,只要和你在Goal 信息中放的一样。请记住还要将 Google Analytics 属性 ID 设置为 Google Analytics 变量。
触发器配置 - 自定义事件,所有自定义事件,您将 form_submitted
放入文本框。
然后,如果需要,您可以创建一个 Event Goal 。您从 Real time > Events
测试它们并通过 Behaviour > Events
.