Hi everyone
I am playing around with Google Analytics asynchronous tracking code and facing a "problem" where I have to have strings within strings in java script called by event handlers such as onClick.
This piece of java script needs to be called when the even handler onBeforeUnload fires:
onbeforeunload="timeTracker._recordEndTime(); _gaq.push(['java script code']);"
So _gaq.push(['java script code']) takes a string of java script code and enqueues it for execution.
The piece of codes needing to be executed is this:
function(){ eTr = _gat._getTrackerByName('eventTracker'); timeTracker._track(eTr, undefined, document.title);}
As you can see the code above function(){} has a string in it. How should those two pieces of code be merged so that everything gets interpreted correct?
onbeforeunload="timeTracker._recordEndTime();
_gaq.push(['function(){ eTr = _gat._getTrackerByName('eventTracker'); timeTracker._track(eTr, undefined, document.title);}']);"
I cannot mix " and ' since the html tags use ". The above with 'code 'string' more code' does (obviously) not work and escaping the quotes \' does not work either.
Any suggestions?
Best regards
Wuhtzu