i need some help with google ecommerce javascript code. As google shows an example of how to implement this function in a website it works fine. But here's the problem: i need to send data to analytics when asp.net button is pressed, so appropriate way to achieve that is to write javascript function, and place it before </head> tag. here's the code:
Code:
<script type="text/javascript">
function sendAnalytics(){

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-27232165-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_addTrans',
    '1334',           // order ID - required
    'Clothing',  // affiliation or store name
    '11.99',          // total - required
    '1.29',           // tax
    '5',              // shipping
    'San Jose',       // city
    'California',     // state or province
    'USA'             // country
  ]);

   // 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
  _gaq.push(['_addItem',
    '1334',           // order ID - required
    'DDD4',           // SKU/code - required
    'T-bag',        	// product name
    'Green Medium',   // category or variation
    '11.99',          // unit price - required
    '1'               // quantity - required
  ]);
  _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();  
  return true;
  }
</script>
on button click function sendAnalytics() is invoked, but it seems that this part of code doesn't work, because analytics doesn't receive any data.
Code:
 (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
any suggestions? Thank you in advance for your help