2012-08-01 48 views
1

提交html表单后,我需要记录AdWords转换。 get_support.html调用contact.php。下面的代码的形式部分:表单提交= AdWords转换

<form method="post" action="contact.php"> 
    <div class="field"> 
     <label>WHAT DO YOU NEED HELP WITH?: <span>*</span></label> 
     <textarea name="message" class="text textarea" ></textarea> 
    </div> 
    <div class="field"> 
     <label>NAME: <span>*</span></label> 
     <input type="text" name="name" class="text" /> 
    </div> 
    <div class="field"> 
     <label>PHONE NUMBER: <span>*</span></label> 
     <input type="text" name="phone" class="text" /> 
    </div> 

    <div class="field"> 
     <label>EMAIL: <span>*</span></label> 
     <input type="text" name="email" class="text" /> 
    </div> 

    <div class="field"> 
     <input type="button" id="send" value="SUBMIT INFO" /> 
     <div class="loading"></div> 
    </div> 

</form> 

这里的contact.php

<?php 
//Retrieve form data. 
//GET - user submitted data using AJAX 
//POST - in case user does not support javascript, we'll use POST instead 
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name']; 
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email']; 
$message = ($_GET['message']) ?$_GET['message'] : $_POST['message']; 

//flag to indicate which method it uses. If POST set it to 1 
if ($_POST) $post=1; 

//Simple server side validation for POST data, of course, you should validate the email 
if (!$name) $errors[count($errors)] = 'Please enter your telephone.'; 
if (!$email) $errors[count($errors)] = 'Please enter your email.'; 
if (!$message) $errors[count($errors)] = 'Please enter your message.'; 

//if the errors array is empty, send the mail 
if (!$errors) { 

    // ====== Your mail here ====== // 
    $to = 'US TECH SUPPORT <[email protected]>'; 
    //sender 
    $from = $name . ' <' . $email . '>'; 

    //subject and the html message 
    $subject = 'FORM-SUBMISSION-VIRUSREMOVALHEROES.COM';  
    $message = ' 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head></head> 
    <body> 
    <table> 
     <tr><td>Phone:</td><td>' . $name . '</td></tr> 
     <tr><td>Email:</td><td>' . $email . '</td></tr> 
     <tr><td>Message:</td><td>' . nl2br($message) . '</td></tr> 
    </table> 
    </body> 
    </html>'; 

    //send the mail 
    $result = sendmail($to, $subject, $message, $from); 

    //if POST was used, display the message straight away 
    if ($_POST) { 
     if ($result) echo 'Help is on the way! We have received your message.'; 
     else echo 'Sorry, unexpected error. Please try again later'; 

    //else if GET was used, return the boolean value so that 
    //ajax script can react accordingly 
    //1 means success, 0 means failed 
    } else { 
     echo $result; 
    } 

//if the errors array has values 
} else {} 


//Simple mail function with HTML header 
function sendmail($to, $subject, $message, $from) { 
    $headers = "MIME-Version: 1.0" . "\r\n"; 
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 
    $headers .= 'From: ' . $from . "\r\n"; 

    $result = mail($to,$subject,$message,$headers); 

    if ($result) return 1; 

    else return 0; 
} 

?> 

而从谷歌对我的形式转换代码填写

echo '<!-- Google Code for Form Submission Conversion Page --> 
<script type="text/javascript"> 
/* <![CDATA[ */ 
var google_conversion_id = 1004137309; 
var google_conversion_language = "en"; 
var google_conversion_format = "3"; 
var google_conversion_color = "ffffff"; 
var google_conversion_label = "H1HvCNOWswQQ3dbn3gM"; 
var google_conversion_value = 0; 
/* ]]> */ 
</script> 
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js&amp;quot;&amp;gt; 
</script> 
<noscript> 
<div style="display:inline;"> 
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1004137309/?value=0&amp;amp;amp;label=H1HvCNOWswQQ3dbn3gM&amp;amp;amp;guid=ON&amp;amp;amp;script=0&amp;quot;/&amp;gt; 
</div> 
</noscript>'; 

我研究这个,只是不能弄清楚如何解决这个问题。任何帮助表示赞赏。

+0

好像它应该是回显当脚本确认没有错误? – Cyclone 2012-08-01 20:03:17

+0

应该在哪里放置回声?无论我在哪里放置Google转换代码,都会收到contact.php的错误,抱歉,意外的错误。请稍后再试 – 2012-08-01 23:07:42

+0

转换代码究竟是从Google出来的吗?您的近似括号似乎已转换为“&”; & GT;' – 2012-08-02 00:39:30

回答

0

Google Adwords转换代码的工作原理是将转换跟踪代码放在“Thank You”页面上。提交表单后,请将用户引导至“感谢您”页面。将转换跟踪代码放置在此页面的源代码中,您将开始注册转化。作为用户访问此页面的唯一合乎逻辑的方式是提交正式填写的联系表单。

此外,还要确保没有其他办法让这个页面除了通过提交表单(使用机器人和脱钩从所有其他网页现场)

+0

不错的选择,但你需要特定的网站的每个窗体的感谢页面。 – user2060451 2017-02-13 02:55:43

+0

不一定,您可以在您的提交链接(utm等)中添加嵌入的标识符,以知道用户从哪个页面引用了哪个表单。如果没有,您的谢谢页面分析将无论如何显示页面跟踪并告诉您用户来自哪个页面。 – masmrdrr 2017-02-14 04:59:19