trying to get javascript variables into Google Analytics code

Posted on 2012-09-20
Last Modified: 2013-11-18

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

Question by:NeilT
    LVL 42

    Accepted Solution

    Yeah, the arguments are all string types. Cast it to string when you set it.

    var genOrderID = String(new Date().getTime());
    LVL 3

    Author Comment

    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"/>
    LVL 3

    Author Closing Comment

    Superb, many thanks
    LVL 42

    Expert Comment

    by:Chris Stanyon
    No idea on the Java stuff, sorry!
    LVL 3

    Author Comment

    :). I tried just adding what I put above and it worked instantly

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    The next wave of Panda releases starts with Panda2.1 After the game-changing Panda2.0 update that caused a reduction in Google search engine referral traffic to a newly affected and larger set of websites, more Panda updates were already in the pip…
    Read about why website design really matters in today's demanding market.
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now