AdWords
2K members online now
2K members online now
Use AdWords conversion tracking and reporting to measure your results. Have a question about Google Analytics? Post it here, on the Google Analytics Community!
Guide Me
star_border
Reply

How to implement Adwords trackingcode in PHP?

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

My site has been build in HTML. It has a contactform which I want visitors to fill in.

One people press the submit button the contact.php file is been activated. There does not appear a new webpage. There only appears a text line above the contactform saying it has been submitted.

 

The conversion has to registered upon the confirmation/activation of the contact.php file.

 

Conversion is been measured in leads with a fixed value.

 

I have embedded the conversioncode as follows:

 

<?php

if(!$_POST) exit;

(script that creates form)......

    // Email has sent successfully, echo a success page.

    echo "<fieldset>";
    echo "<div id='success_page'>";
    echo "<h4>E-mail is succesvol verstuurd.</h4>";
    echo "<p>Bedankt $name, ik heb jouw bericht ontvangen.</p>";
    echo "</div>";
    echo "</fieldset>";

} else {

    echo 'ERROR!';

}

?>

<!DOCTYPE html>
<html lang=”en”>

<!-- Google Code for Contactform submission Conversion Page --> <script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 945347504;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "fjsUCJzv2GIQsLfjwgM"; var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript"  
src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""  
src="//www.googleadservices.com/pagead/conversion/945347504/?label=fjsUCJzv2GIQsLfjwgM&amp;guid=ON&amp;scri...
</div>
</noscript>
</html>

 

 

Have I done things right?

2 Expert replyverified_user

Re: How to implement Adwords trackingcode in PHP?

Top Contributor
# 2
Top Contributor
Hi Shana H,

It's little hard to tell. If you are sending the success message with the original content but not displaying until the form is submitted, this could be ok.

What it looks like is you are sending the conversion code along with the blank form. That would record a conversion when the user hits the page, not when the form is submitted. In other words, every click on your ad would report as a conversion.

If you are delivering the confirmation as a callback (or AJAX), this won't work. Javascript embedded in callback content does not run, not even the noscript portion. If that' s the case, the easy thing to do is to return only the image part of the script, the part between the noscript tags, not including the noscript tags.

An alternative is to use event tracking in Analytics to record the conversion, but that would happen on the click, regardless if the submission was successful.

Best of Luck!

Pete
petebardo -- Deadhead doing AdWords
Marked as Best Answer.
Solution
Accepted by Mini-CM (Community Manager)
December 2015

Re: How to implement Adwords trackingcode in PHP?

Rising Star
# 3
Rising Star

Hey Shanna, how are things?

  

Have you tested this? Got any results? If that doesn't work, try to add you PHP code inside the HTML structure, something like:

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>

<body>
<?php
if(!$_POST) exit;
(script that creates form)......
    // Email has sent successfully, echo a success page.

    echo "<fieldset>";
    echo "<div id='success_page'>";
    echo "<h4>E-mail is succesvol verstuurd.</h4>";
    echo "<p>Bedankt $name, ik heb jouw bericht ontvangen.</p>";
    echo "</div>";
    echo "</fieldset>";

} else {
    echo 'ERROR!';
}
?>

<!-- Google Code for Contactform submission Conversion Page --> <script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 945347504;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "fjsUCJzv2GIQsLfjwgM"; var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript"  
src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""  
src="//www.googleadservices.com/pagead/conversion/945347504/?label=fjsUCJzv2GIQsLfjwgM&amp;guid=ON&amp;scri...
</div>
</noscript>
</body> </html>

Also, if that doesn't work, you can try and install Google Tag Manager on your website as configure it to fire the conversions code upon form submit:

https://support.google.com/tagmanager/answer/3415369?hl=en#FormSubmitListener

 

Hope this helps.


Leandro Martinez | Basta1Click

Re: How to implement Adwords trackingcode in PHP?

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

I'm trying to add two screendumps of how the form works/what happens when you submit it.

 

I have tried to add the html code within the php code, but then the php code shows failures.

 

I've only just set the conversion in Adwords, so it hasn't been verified yet by Google. But I've got a feeling that the way I implemented the code is not the way to do it.

 

 

Re: How to implement Adwords trackingcode in PHP?

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

For some reason I can't add a photo.

 

What happens with the form when you submit it:

 

The formfields disappear and a thank you message (text only) appears in place of the form.

How to implement Adwords trackingcode in PHP?

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

That is the exact thing i am doing, but it does not work.