?
Solved

Using PHP inside of Javacript - Google Conversion Tracking

Posted on 2008-10-07
2
Medium Priority
?
192 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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

809 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