Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfoutput within javascript

LEGEND ,
Sep 03, 2008 Sep 03, 2008
Just trying to install the google ecom tracking code supplied by google. It
does some nice things like the actual ROI depending on pay per click word
chosen.

Ive never had to output cold fusion varibles beofre within javascript. Do i
need to use use the toscript tag or would the code below work? Any help
appreciated.


<!----google e-com tracking--------->
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-1");
pageTracker._trackPageview();

<!------Output query results into javascript-------->
<cfoutput query="order2">

pageTracker._addTrans(

"#i_orderid#", // Order ID

"#d_grandtotal#" // Total

);
</cfoutput>

// add item might be called for every item in the shopping cart
// where your ecommerce engine loops through each item in the cart and
// prints out _addItem for each

<cfoutput query="lines" >
pageTracker._addItem(
"#lines.i_orderid#", // order ID
"#lines.s_partno#", // SKU/code - required
"#lines.d_price#", // unit price - required
"#lines.i_quantity#" // quantity - required
);
</cfoutput>
pageTracker._trackTrans();
</script>


TOPICS
Getting started
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2008 Sep 04, 2008
If you want to know if the code works, run it.

There are a couple of ways to mix cold fusion variables with javascript. One is the to_script tag. The other is to surround the entire javascript block with cfoutput.

In your case, to_script seems like a better approach. Make each query column a js array.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2008 Sep 04, 2008
Hi Dan

i did run the code and a part of it works. a transcation with google gets
recorded however all the other parameters are not recorded. I suspect this
is due to my syntax.

Im a hack and dont know too much about js arrays but from what ive been able
to find on the web, would it look something like this?

Should they be js variables do you think?


<!----google e-com tracking--------->
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-1");
pageTracker._trackPageview();

<!------Output query results into javascript-------->
<cfoutput query="order2">

pageTracker._addTrans(

var #toScript(i_orderid, "OrderID")#; // Order ID

var #toScript(d_grandtotal, "Total")#; // Total

);
</cfoutput>





"Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
news:g9oiia$t5s$1@forums.macromedia.com...
> If you want to know if the code works, run it.
>
> There are a couple of ways to mix cold fusion variables with javascript.
> One
> is the to_script tag. The other is to surround the entire javascript
> block
> with cfoutput.
>
> In your case, to_script seems like a better approach. Make each query
> column
> a js array.
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 04, 2008 Sep 04, 2008
I've only done this once, and since it had to do with a frequent asked question (related selects), I made a web page. http://www.pathcom.com/~bracuk/code/RelatedSelects.htm

Step 2 is where I create my cf arrays. Step 4 is where I convert and use them in js.

If you've not programmed in languages other than CF before, be aware that pretty much all of them start their arrays at element 0, unlike CF which starts at element 1.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2008 Oct 09, 2008
LATEST
Thanks in advance for any feedback.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources