Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

trying to get javascript variables into Google Analytics code

Hi

I'm trying to get a few variables into a bit of Google Analytics code but not sure if I'm doing it right.

I want the var genOrderID I have assigned to be passed as the 1st param in addTrans and addItem, does the code below seem ok or should it be in '' 's if so wont it just be supplied as text?

Is there any way I can actually see the generated JS code, ive tried firefor generated source but it just shows as below?

Thanks
Neil

<script type="text/javascript">

var genOrderID = new Date().getTime();

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-1']);
_gaq.push(['_trackPageview']);

_gaq.push([
'_addTrans', genOrderID, // order ID - required     
'', // affiliation or store name     
'100.00', // total - required     
'', // tax     
'', // shipping     
'', // city     
'', // state or province     
''  // country   
]);


_gaq.push([
'_addItem', genOrderID, // order ID - required     
'CTX', // SKUcode - required     
'Council Tax', // product name     
'', // category or variation     
'100.00', // 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);
})();

</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Neil Thompson

ASKER

excellent thanks, I guess you dont know how to also drip a Java Form Bean in there do you? I've got one in format

<bean:write name="payCTXForm" property="paymentResponse.paymentReference"/>
Superb, many thanks
No idea on the Java stuff, sorry!
:). I tried just adding what I put above and it worked instantly