简体   繁体   English

如何使用Google Analytics(分析)和PHP追踪提交表单

[英]How to track a form on submit with Google Analytics and PHP

I want to track a form with GA and setup GOAL's i need a proper code that work when the form is submited. 我想用GA跟踪表单并设置目标,我需要一个正确的代码来提交表单。

my code is: 我的代码是:

<?php
if(isset($_GET['button'])){
  GA code here..
}

?>

there is difrent examples out there but, i need one thats actual work, so if anyone have example that work, im intressed in such. 那里有不同的例子,但是,我需要那是实际的工作,因此,如果有人有这样的例子,那么就很重要。

Save the google analytics script in a file say analyticstracking.php, then include the file as follows: 将Google Analytics(分析)脚本保存在一个名为analyticstracking.php的文件中,然后按如下所示添加文件:

<?php   include_once("analyticstracking.php"); ?>

The code to be saved in analyticstracking.php can be found from google analytics site. 要保存在analyticstracking.php中的代码可以在Google Analytics(分析)网站上找到。

Trivial answer, expanding on your own code example: 简单的答案,扩展您自己的代码示例:

<?php
if(isset($_GET['button'])){
?>
<script>
ga('send', 'event', 'Fom', 'submit', 'some label');
</script>
<?php
}
?>

Closing and opening the php tags means the code in the if condition will only be executed when the condition is met. 关闭和打开php标签意味着if条件中的代码仅在满足条件时才会执行。 This is a less than elegant solution, but workable (as long as the tracker is created somewhere before in the page). 这不是一个优雅的解决方案,但可行(只要在页面之前的某个位置创建了跟踪器)。 It would be better to create a dedicate url for a thankyou-page and track that. 最好为thankyou-page创建一个专用URL并对其进行跟踪。

You need to call the track event api for ga 2 https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide for universal analytics https://developers.google.com/analytics/devguides/collection/analyticsjs/events 您需要调用ga 2的跟踪事件api https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide进行通用分析https://developers.google.com/analytics/devguides/collection/analyticsjs /事件

If you want to do it PHP side see this https://github.com/thomasbachem/php-ga 如果您想在PHP方面做到这一点,请参阅此https://github.com/thomasbachem/php-ga

if jquery/ js then 如果jquery / js然后

for ga2 对于ga2

$( "form" ).submit(function() {

_gaq.push(['_trackEvent', 'formsubmit', 'form', 'form was submitted']);

});

or for universal analytics 或用于通用分析

$('form').submit(function() {
  ga('send', 'event', 'form', 'submit', 'form submitted');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Google Analytics(分析)中跟踪表单提交为页面视图? - How to track form submit as page view in Google Analytics? 如何使用Google Analytics(分析)跟踪“提交”按钮? - How to track the “Submit” button using Google Analytics? 点击表单提交后,在Google Analytics中跟踪事件 - Track event in google analytics upon clicking form submit Google Analytics(分析)-如何在用户提交表单时跟踪他们的登录ID - Google Analytics - How to track logged in user's ID when they submit a form 如何使用Google Analytics(分析)跟踪表单提交 - How to track a form submission using Google Analytics 如何使用PHP在重定向页面上使用Google Analytics跟踪? - How to track with Google Analytics on a redirection page with PHP? Google Analytics-跟踪表单提交 - Google Analytics - track form submission 如何根据提交的表单在Google Analytics(分析)中跟踪转化? - How do I track a conversion in Google Analytics Based on Form Submission? 如何使用jQuery或JavaScript准确跟踪Google Analytics(分析)中的表单放弃 - How to accurately track Form Abandonment in Google Analytics using jQuery or JavaScript 如何在嵌入式表单上跟踪Google Analytics(分析)自定义事件? - How to Track a Google Analytics Custom Event on an Embedded Form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM