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

  • 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? – Romans-8---31-39 Jun 21 '13 at 13:50
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';
|improve this answer|||||
  • Many thanks Siebird - that has fixed this issue :D – Cole Henley Jun 21 '13 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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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