trying to get javascript variables into Google Analytics code


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?


<script type="text/javascript">

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

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

'_addTrans', genOrderID, // order ID - required     
'', // affiliation or store name     
'100.00', // total - required     
'', // tax     
'', // shipping     
'', // city     
'', // state or province     
''  // country   

'_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') + '';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);


Open in new window

Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?
Chris StanyonCommented:
Yeah, the arguments are all string types. Cast it to string when you set it.

var genOrderID = String(new Date().getTime());
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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"/>
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Superb, many thanks
Chris StanyonCommented:
No idea on the Java stuff, sorry!
Neil ThompsonSenior Systems DeveloperAuthor Commented:
:). I tried just adding what I put above and it worked instantly
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.