在表单提交时触发转化跟踪代码

发布于 2024-08-14 11:08:46 字数 1013 浏览 2 评论 0原文

我有一个 PHP 表单,它在提交时通过 mail() 发送表单数据,然后如果成功将它们返回到引用页面(换句话说,将它们保持在与表单相同的页面上)并将 ?success=TRUE 附加到 URL。

问题是,如何实现 AdWords 和 Yahoo Search Marketing 转换代码片段以仅在提交表单时触发?出于功能目的,遗憾的是,在提交时将它们发送到另一个页面是不可行的,而这本来是最简单的方法。

下面是表单提交操作中用于邮寄结果并将其发送回主页的相关代码。我有预感,它可能就像在最后的 if 语句中输出转换跟踪代码片段一样简单,但我不确定这是否正确或正确执行此操作的语法。

if ( isset($_POST['sendContactEmail']) )
    {

$fname = $_POST['posFName'];
$lname = $_POST['posLName'];
$phone = $_POST['posPhone'];
$email = $_POST['posEmail'];
$note = $_POST['posText'];

$to = $yourEmail;
$subject = $yourSubject;

$message = "From: $fname $lname\n\n Phone: $phone\n\n Email: $email\n\n Note: $note";

$headers = "From: ".cleanPosUrl($_POST['posFName']. " " .$_POST['posLName'])." \r\n";

$headers .= 'To: '.$yourName.' '."\r\n";

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

if ( @$mailit ) {
        header('Location: '.$referringPage.'?success=true');
        }

else {
        header('Location: '.$referringPage.'?error=true');
        }
    }

I have a PHP form that mail()s the form data on submit and then if successful returns them to the referring page (in other words keeping them on the same page as the form) and appends ?success=TRUE to the URL.

The question is, how would I implement the AdWords and Yahoo Search Marketing conversion code snippets to trigger only when the form is submitted? For functionality purposes, it is unfortunately not feasible to send them to another page on submit which would have been the easiest way to do it.

The relevant code from the form submit action that mails the results and sends them back to the homepage is below. I have a hunch it might be as simple as outputting the conversion tracking code snippets in the if statement at the end there but I'm not sure if that is correct or the syntax to properly do that.

if ( isset($_POST['sendContactEmail']) )
    {

$fname = $_POST['posFName'];
$lname = $_POST['posLName'];
$phone = $_POST['posPhone'];
$email = $_POST['posEmail'];
$note = $_POST['posText'];

$to = $yourEmail;
$subject = $yourSubject;

$message = "From: $fname $lname\n\n Phone: $phone\n\n Email: $email\n\n Note: $note";

$headers = "From: ".cleanPosUrl($_POST['posFName']. " " .$_POST['posLName'])." \r\n";

$headers .= 'To: '.$yourName.' '."\r\n";

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

if ( @$mailit ) {
        header('Location: '.$referringPage.'?success=true');
        }

else {
        header('Location: '.$referringPage.'?error=true');
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦爱 2024-08-21 11:08:46

在 if 语句中输出它是可能的,但是您发布的脚本添加了另一种方法来执行此操作,因为它重定向到 $referringPage - 如果邮件已成功发送。这是您想要跟踪转化的唯一事件。

因此,编辑$referringPage(包含表单字段的页面)的代码并添加:

<?php
if($_GET['success'] == 'true') {
    echo "...";
}
?>

“...”当然必须替换为Google给您的Adwords转换代码。
如果您将其添加到您的问题中,我什至可以将其添加到我的答案中。

Outputting it in the if-Statement would be a possibility, but the script you posted adds another way to do it as it redirects to the $referringPage - if the mail was successfully sent. And that's the only event you want to track a conversion.

So edit the code of $referringPage (the page that holds the form fields) and add:

<?php
if($_GET['success'] == 'true') {
    echo "...";
}
?>

"..." ofcourse has to be replaced by the Adwords conversion Code Google gave you.
If you add it to your question, I could even add it to my answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文