0

I'm using an embedded template to include the for my site. I want to use Google Analytics custom variables to track visitor information for logged in users so thought I could selectively show the Analytics code if a user is logged in using the {if logged_in} conditional.

So in a tag have put the following:

{if logged_in}
// define a Visitor-level Custom Variables based on the member ID
_gaq.push(['_setCustomVar',1,'Member ID','{member_id}',1]); 
{/if}

If the user is logged in then the code works as expected. However if a member is not logged in the template is writing the following to my HTML:

{if FALSE}
// define a Visitor-level Custom Variables based on the member ID
_gaq.push(['_setCustomVar',1,'Member ID','0',1]); 
{/if}

Any thoughts why this might be happening? I would expect that if nobody is logged in the site would return nothing.

Cheers,

Cole

1
  • I tried your exact code on 2.6.1 and it works fine, logged in or out. Is it possible there's something somewhere else that is disrupting the conditional? Jun 21, 2013 at 13:50

2 Answers 2

1

Since your conditional is inside of <script> tags, EE by default prevents the advanced conditional from parsing. Add this to your config:

$config['protect_javascript'] = 'n';
1
  • Many thanks Siebird - that has fixed this issue :D Jun 21, 2013 at 14:53
0

I would suggest not using {if False} and instead using {if:else} and then specifying your analytics code from there.

Because you're not doing that, I would speculate that EE doesn't know what "else" to do and so just tries to go with what it has, which is nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.