0

我被要求在网站订单收据页面上部署价值点击跟踪像素。数据必须动态放置到 iframe 的 src 中。

我已将正确的数据声明为变量,如下所示:

<script type="text/javascript">
//makes a copy of the total order revenue
var totalPrice = jQuery('.veryImportant.ordertotal div').html();
jQuery('#buttons').append('<p id="totalPrice">'+totalPrice+'</p>');
//removes the £ pound symbol from the duplicated string
var val = jQuery('#totalPrice').html();
jQuery('#totalPrice').html(val.substring(1, val.length));
//required variables
var orderid = jQuery('.ordernumber strong').text(); //order ID number
var revenue = jQuery('#totalPrice').text(); // total order revenue
var quantity = jQuery('#totalQuantity').text(); //quantity per table row/product name
//testing the variables print the correct values
alert(orderid + " " + revenue + " " + sku + " " + quantity);
</script>

(对于任何想知道页面中已经存在的“sku”的人,所以我很幸运)

我需要变量在这个 iframe 中动态打印它们的值,我将把它放在上面的 jQuery 下:

<iframe src="https://secure.img-cdn.mediaplex.com/0/24663/universal.html?page_name=sale&Sale=1&Amount={' + revenue + '}&Quantity={' + quantity + '}&mpuid={' + sku + ',' + orderid + '}" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe>

上面我尝试添加变量名,但用空格和 + 符号括起来,但这不起作用。它只是在浏览器中准确显示上述内容。

任何想法,人们?

4

1 回答 1

0

好的,所以我设法解决了这个问题。该方法相当冗长,但是我不得不解决一些障碍(因此我必须复制和移动一些数据)

<!-- order confirmation page VALUE CLICK -->
<venda_block mode=value,<venda_tpxt mode=get,name=track>=orderreceipt><!-- applies this     code block to the order receipt page only -->
<!-- HTML -->
<p id="valueClickSrc"></p><!-- acts as a store for the js to construct and deploy the dynamic src -->
<iframe id="iframe1" src="#" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe> <!-- the actual      tracking iframe which will be populated by js -->
<p id="totalQuantity" style="position:relative; z-index:9999; background:#066; font-size:14px; color:#FFF;"><venda_shopcart mode=getqty></venda></p><!-- serves to 'wrap' the quantity so that it can be selected by id -->
<!-- witch craft -->
<script type="text/javascript">
var totalPrice = jQuery('.veryImportant.ordertotal div').html(); //grabs the order total     price from the receipt and stores it in a variable
jQuery('#buttons').append('<p id="totalPrice" style="display:none;">'+totalPrice+'</p>'); //prints the total price inside a p tag so that it can be selected
var val = jQuery('#totalPrice').html(); //grabs the order total price from the newly printed p tag above
jQuery('#totalPrice').html(val.substring(1, val.length)); //removes the first character from the #totalPrice string (in this case, the unwanted £ GBP pound symbol)
var orderid = jQuery('.ordernumber strong').text(); //order ID number
var revenue = jQuery('#totalPrice').text(); // total order revenue
var quantity = jQuery('#totalQuantity').text(); //quantity per table row/product name
// sku is a variable that appears to already be in side the default checkout page js. I got lucky with that one.
alert(orderid + " " + revenue + " " + sku + " " + quantity); //tests that all variables are printing as they should
jQuery('#valueClickSrc').html('https://secure.img-cdn.mediaplex.com/0/24663/universal.html?page_name=sale&Sale=1&Amount=%7b'+revenue+'%7d&Quantity=%7b'+quantity+'%7d&mpuid='+sku+'id'+ orderid); //writes the dynamic url with a combination of text and variables. This is placed inside the <p> above called #valueClickSrc
var valueClickSrc = jQuery('#valueClickSrc').html(); //stores the content of the <p> above into a variable
jQuery('#iframe1').attr('src', valueClickSrc); //applies the content from #valueClickSrc into the src attribute of the iframe
</script>
</venda_block>
<!-- End Value Click tag -->

对于在 Venda 平台上工作的任何人,他们可能会发现这很有用。

如果有人有建议,我很乐意听到。

于 2013-03-28T16:28:41.163 回答