1

I'm trying to set the User-ID for Google's new Universal Analytics, but it keeps erring saying " SyntaxError: Unexpected token '{' ".

Here is my code;

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXXX-X', 'auto');
{if logged_in}
ga('set', '&uid', {{{member_id}}});
{/if}
ga('send', 'pageview');
</script>

I have tried this with $env_config['protect_javascript'] = 'y' and $env_config['protect_javascript'] = 'n';.

1 Answer 1

2

Why do you have 3 sets of parenthesis around the member_id tag?

Does it work if you simply use {member_id}?

EDIT (after comments) I'm not completely sure how this should be set up as I've never used this (will need to get up to speed on it though) but based on what I see in the docs does this work;

{if logged_in}
    ga('create', 'UA-XXXX-Y', { 'userId': '{member_id}' })
{if:else}
    ga('create', 'UA-XXXXXXXX-X', 'auto');
{/if}

I'm not sure why the docs show UA-XXXX-Y for the user ID section.

3
  • 2 of the parenthesis are required for Universal Analytics to track a user ID as {{USER_ID}}); May 14, 2014 at 11:21
  • Looking at the docs here developers.google.com/analytics/devguides/collection/… it looks slightly different to how you're doing it.
    – foamcow
    May 14, 2014 at 11:42
  • Indeed, it's a bit confusing because the developer docs show the way above. But when you create a new Universal property with User ID, it shows the markup i have above. May 14, 2014 at 11:54

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.