Solved

Using PHP inside of Javacript - Google Conversion Tracking

Posted on 2008-10-07
2
186 Views
Last Modified: 2013-12-12
I'm attempting to use a google conversion tool. It requires me to drop some google code into one of my web pages.  

What I want to know is if it is possible or not to use php inside of javascript.

I have something like this.
<!-- Google Code for Purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 9999999999;
var google_conversion_language = "en_US";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
if (<?=$order_amount;?>) {
  var google_conversion_value = <?=$order_amount;?>;
}
var google_conversion_label = "8zZ1dfa41DmKj-Aw";
//-->
</script>
<script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/9999999/?value=<?=$order_amount;?>&amp;label=8zZ1CK3431DDmKj-Aw&amp;script=0"/>
</noscript>
 
Each place I put <?=$order_amount;?> is what I'm concerned about.  Will this work?

Open in new window

0
Comment
Question by:cstormer
  • 2
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22663088
>>What I want to know is if it is possible or not to use php inside of javascript.
That should work ok. The Google code requires just "plain" javascript, but the php code you supplied is  executed on the server and the value of $amount should be seen in the javascript code only, not the php.

NOTE: for it work, the file containing the code you posted above should be a .php file, not a .js file.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22668847
glad to help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question