Solved

Using PHP inside of Javacript - Google Conversion Tracking

Posted on 2008-10-07
2
181 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
Comment Utility
>>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
Comment Utility
glad to help
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now