?
Solved

Using PHP inside of Javacript - Google Conversion Tracking

Posted on 2008-10-07
2
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 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