...

View Full Version : GA Event Tracking OnClick troubleshooting



decore
07-12-2012, 08:09 PM
Hello friends,
I'm struggling here to insert a _gaq.push(['_trackEvent', on a button at my webstite.

The original button looks like this:

<button type="submit" class="button" title="Login" onclick="veriform.verify(1)">'. LANG::_('login') .'</button>

What i tried to do is:

<button type="submit" class="button" title="Login" onclick="veriform.verify(1);_gaq.push(['_trackEvent', 'IniciarProjeto', 'Cadastro', 'EntrarCadastrado',]);">'. LANG::_('login') .'</button>

But my page appeared blank...

Can anybody help me?

Fou-Lu
07-12-2012, 08:48 PM
Syntactical issue. If you would actually post the entire line in a PHP markup block, you'd see the color change from red to blue.
You need to escape those single quotes.


to demonstrate this:


echo '<button type="submit" class="button" title="Login" onclick="veriform.verify(1);_gaq.push(['_trackEvent', 'IniciarProjeto', 'Cadastro', 'EntrarCadastrado',]);">'. LANG::_('login') .'</button>';


BTW, enabling your error reporting would tell you what the problem is:


ini_set('display_errors', 1);
error_reporting(E_ALL);



Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on line X

decore
07-12-2012, 09:32 PM
Thx a lot Fou-Lu,

Can you share the final code I should use at my site?! I would not know how to scape those single quotes...

Fou-Lu
07-12-2012, 09:35 PM
Simply place a \ in front of any single quote that is used within that string.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum