![]() |
XCart removing code from script. How to get code on page?
I would like to add code (below) to the <head>.
I've tried putting it directly into the page home.tpl. It shows in the template editor, but XCart removes part of the code when loading the page. I've tried calling it as a separate .tpl (template) file into the page. Xcart removes part of the code when loading the page. I've tried putting it into the common.js file. The code doesn't load. I've tried building a new HTML page, pulling that HTML page into the template in a 1x1 iframe. The frame and code loads, but then doesn't do the tracking I want it to because it's loading in a frame. No matter what I do, XCart is removing everything between { and } the code that I've highlighted in Dark Green below. How do I get this full code to show up on the page inside of <head></head> and get XCart to leave it alone? Thank-you! Andrew http://www.MattressInsider.com Here is the full code (with our ID changed to X's): <!-- Begin SpringMetrics --> <script type='text/javascript'> var _springMetq = _springMetq || []; _springMetq.push(['id', 'XXXXXXXXXX']); ( function(){ var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = ('https:' == document.location.protocol ? 'https://d3rmnwi2tssrfx.cloudfront.net/a.js' : 'http://static.springmetrics.com/a.js'); var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); } )(); </script> <!-- End SpringMetrics --> |
Re: XCart removing code from script. How to get code on page?
Probably this: http://help.x-cart.com/index.php?title=X-Cart:Customizing_storefront#JavaScript_in_template s
Javascript and smarty share syntax, so you have to let smarty know not to interpret the javascript. --- |
Re: XCart removing code from script. How to get code on page?
Yes, just put {literal}tags{/literal} around your javascript code.
|
Re: XCart removing code from script. How to get code on page?
Thanks very much for this help.
It works! Further question... I have a separate piece of code to track conversions. (This is for SpringMetrics.) This code is tracking the conversion itself, but not passing the value of that conversion back. Here are three pieces of code I've tried... ------------ OPTION 1 ------------ <!-- SpringMetrics Conversion Code for mattressinsider --> {literal} <script type="text/javascript"> _springMetq.push(["setdata", {revenue: "{/literal}{$order.total}{literal}"}]); _springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]); _springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]); _springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }]); _springMetq.push(["convert", "sale" ]); </script> {/literal} <!-- SpringMetrics Conversion Code for mattressinsider --> ------------ OPTION 2 ------------ {literal} <script type="text/javascript"> _springMetq.push(["setdata", {revenue: "{/literal}{$order.order.subtotal}{literal}"}]); _springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]); _springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]); _springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }]); _springMetq.push(["convert", "sale" ]); </script> {/literal} <!-- SpringMetrics Conversion Code for mattressinsider --> ------------ OPTION 3 ------------ <script type="text/javascript">{literal} _springMetq.push(["setdata", {revenue: {/literal}"{$order.order.subtotal}"{literal}}]); _springMetq.push(["convert", "sale" ]); </script> |
Re: XCart removing code from script. How to get code on page?
You've got loads of {literal} tags in the actual code itself - where did they come from???
They also seem to close then open as well! Get rid of all those literal tags - you just need them before and after the <script>, as you have in #1 and #2 - but just without anything in between. |
Re: XCart removing code from script. How to get code on page?
I've tried that, but it doesn't actually put in the order value. So I thought I would have to turn on and off the {literal} in order to get it to know the difference between the Javascript and the Smarty tag.
What I've got on the site now is: <!-- SpringMetrics Conversion Code for mattressinsider --> {literal} <script type="text/javascript"> _springMetq.push(["setdata", {revenue: "{$order.total}"}]); _springMetq.push(["setdata", { "orderId": "{$order.orderid}" }]); _springMetq.push(["setdata", { "email": "{$order.email}" }]); _springMetq.push(["setdata", { "promoCode": "{$order.coupon}" }]); _springMetq.push(["convert", "sale" ]); </script> {literal} <!-- SpringMetrics Conversion Code for mattressinsider --> Any other thoughts? By the way, thanks so much for your help and your quick reply! |
Re: XCart removing code from script. How to get code on page?
OK, yes, I see what you did now actually.
Are you getting any of the other values through? |
Re: XCart removing code from script. How to get code on page?
None of the values seem to be coming through. By the way, in the above code, the second {literal} is actually {/literal}
|
Re: XCart removing code from script. How to get code on page?
And is all the rest of the code in the right places and working ok?
|
Re: XCart removing code from script. How to get code on page?
And did any value come through at all with any of the code you tried?
|
Re: XCart removing code from script. How to get code on page?
Here's the code I get on the confirmation page.
<script type="text/javascript"> _springMetq.push(["setdata", {revenue: ""}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> |
Re: XCart removing code from script. How to get code on page?
Have you used webmaster mode to ensure that the smarty variables you are using are available and correct for whatever page this is on?
You can also use ldelim if you find it easier: http://www.smarty.net/docsv2/en/language.function.ldelim.tpl --- --- |
Re: XCart removing code from script. How to get code on page?
Quote:
I'm not sure what this means - as far as testing it. I've just now seen Webmaster Mode for the first time, so will check that shortly. This is on /customer/main/order_message.tpl because it's tracking the conversion of the sale. Is there somewhere else I would put it to make it work better? How would I know what the correct smarty variables would be? Thanks for your help! |
Re: XCart removing code from script. How to get code on page?
Webmaster mode tells you all the smarty variables available on whichever page you need the code to be. You can look at the X-Cart documentation for Webmastermode, or you might find the tutorials that Totaltec has created useful. Just search for him on the the forum and follow the links in his signature.
--- |
Re: XCart removing code from script. How to get code on page?
Webmaster Mode doesn't give me a list of variables.
It just gives me a list of templates referenced for the page I'm on. ![]() ![]() ![]() ![]() ![]() ![]() ![]() etc. (X-cart.com doesn't let me post the full list, but it's just a list of templates.) |
Re: XCart removing code from script. How to get code on page?
Quote:
Click on "Show Variables" in the debug console. |
Re: XCart removing code from script. How to get code on page?
Ah -- you are in version 4.1.x, yes? There's a slightly different way to do it.
See this thread: http://forum.x-cart.com/viewtopic.php?t=17601 |
Re: XCart removing code from script. How to get code on page?
Here's the code that seems to work to do everthing correctly, except put the variables in.
Here's what's in order_message.tpl: <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {literal}{revenue: "{/literal}{$order.order.subtotal}{literal}"}]); _springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]); _springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]); _springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }{/literal}]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> Here's what's output on https://www.mattressinsider.com/cart.php?mode=order_message&orderids=12816&keep_ht tps=yes <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: ""}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> Except it's spaced properly when I view the code: <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: ""}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> Here are the variables I have tried in revenue: {$order.total} {$order.order.subtotal} What other variables might work there to put in the revenue? Is there a guide or list of variables somewhere? Thank-you so much for helping with this. |
Re: XCart removing code from script. How to get code on page?
Based on this post:
http://forum.x-cart.com/showthread.php?t=62458 I also just tried: {foreach from=$orders item=order} ... {$order.total} ... {/foreach} Which output this: <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: "... ... "}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> I also just tried it without the ..., which output this: <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: "... ... "}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> |
Re: XCart removing code from script. How to get code on page?
Don't "try" - go get the actual variable. I gave you the link.
|
Re: XCart removing code from script. How to get code on page?
Based on the same post,
I tried this (which I know is putting PHP inside of Javascript, but I'm unsure what else to do here...): <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {literal}{revenue: "{/literal}if (<? echo $order.total ?>) {<? echo $order.total ?>;}{literal}"}]); _springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]); _springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]); _springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }{/literal}]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> Which output this: <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: "if (<? echo $order.total ?>) "}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> I also tried this: <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {literal}{revenue: "{/literal}{<? echo $order.total ?>;}{literal}"}]); _springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]); _springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]); _springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }{/literal}]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> Which output this: <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: ""}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> |
Re: XCart removing code from script. How to get code on page?
Quote:
Where is the debug console? I changed smarty.php, and turned on Webmaster mode... |
Re: XCart removing code from script. How to get code on page?
I switched the code in smarty.php, but it's still showing templates, not variables, in the popup.
|
Re: XCart removing code from script. How to get code on page?
General settings.
http://help.x-cart.com/index.php?title=X-Cart:Editing_Skin_Files#Using_Debugging_Console You have to search the docs. 99% of the time, it's there for you! |
Re: XCart removing code from script. How to get code on page?
Okay... that was a stretch for me, but based on all the help offered in this post, as well as here:
http://forum.x-cart.com/showthread.php?t=44543 I was able to get the variables to display in debug mode. Here are the relevant variables: {$orderids}"12817"{$orders}Array (1) 0 => Array (4) order => Array (77) orderid => "12817" login => "anonymous-13353" membership => "" total => "329.00" giftcert_discount => "0.00" giftcert_ids => "" subtotal => "329.00" discount => "0.00" coupon => "" coupon_discount => "0.00" shippingid => "0" tracking => "" shipping_cost => "0.00" tax => "0.00" taxes_applied => "N;" date => "1362493877" status => "Q" payment_method => "Phone Ordering" email => "123testing@readingrainbow.com" So I put in this code: <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {literal}{revenue: "{/literal}{$orders.order.total}{literal}"}]); _springMetq.push(["setdata", { "orderId": "{/literal}{$orderids}{literal}" }]); _springMetq.push(["setdata", { "email": "{/literal}{$orders.order.email}{literal}" }]); _springMetq.push(["setdata", { "promoCode": "{/literal}{$orders.order.coupon}{literal}" }{/literal}]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> Which gives this output: <script type="text/javascript"> _springMetq.push(["setdata", {revenue: ""}]); _springMetq.push(["setdata", { "orderId": "12817" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --></div> Finally the Order ID works. So I assume I'm close now. How do I get the rest of the fields to work? The email field is at the same level in the tree as the other fields. Thank-you! |
Re: XCart removing code from script. How to get code on page?
1 Attachment(s)
Shoot. The tree structure went away. Please see screenshot.
|
Re: XCart removing code from script. How to get code on page?
Solved!
YAY!!! Thank-you SO much for your help. Was a much longer process than anticipated, but good to go now! Here is the XCart code for making Spring Metrics work with the version of XCart we are using. <!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {literal}{revenue: "{/literal}{$orders.0.order.total}{literal}"}]); _springMetq.push(["setdata", { "orderId": "{/literal}{$orderids}{literal}" }]); _springMetq.push(["setdata", { "email": "{/literal}{$orders.0.order.email}{literal}" }]); _springMetq.push(["setdata", { "promoCode": "{/literal}{$orders.0.order.coupon}{literal}" }{/literal}]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --> |
All times are GMT -8. The time now is 09:57 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.