[英]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.