In cart insert subtotal into Google tracking code conversion value field

Started by Valdez360, November 02, 2013, 12:57:45 PM

Previous topic - Next topic

Valdez360

Is there a way that I can, in the cart, insert the cart subtotal into Google tracking code conversion value field?

How can I use jQuery to evaluate <span id="tt_order_subtotal"></span> from the cart into a variable and thence to an integer.?

I would be very grateful for just even a rough pointer?

Valdez360

In case anyone ever wants to try this here is my answer, although I do not even know if a dynamic conversion value will upset the Google machine or be accepted:

<div id="tracking_div">
<script type="text/javascript">

jQuery( document ).ready(function() {
setTimeout(valDelay, 5500)
function valDelay(){
google_conversion_value = jQuery('#tt_order_subtotal').text().match(/\d+/)[0];
var script = document.createElement('script');
script.src = "//www.googleadservices.com/pagead/conversion.js";
document.getElementsByTagName('head')[0].appendChild(script);
}
});
/* <![CDATA[ */
var google_conversion_id = 961089431;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "m7kOCMmgxwgQl5-kygM";
var google_conversion_value;
var google_remarketing_only = false;
/* ]]> */
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/961089431/?value=10&amp;label=m7kOCMmgxwgQl5-kygM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>


I have not uploaded it in anger.