Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Javascript Google Analytics problem

    Hi, i have 1 site with three different brands (three ID numbers). I have made a javascript if-statement but it doesnt work. Somebody see some wrong here, I think it should work properly. Thanks in advance $language and $brand is set...

    <script type="text/javascript">

    var accountId;
    var url;

    if($language == 'test') {
    if($brand = '1') {
    accountId = 'UA-xxxxx-1'
    url = '1.com'
    } else if ($brand = '2') {
    accountId = 'UA-xxxxx-2'
    url = '2.com'
    } else if ($brand = '3') {
    accountId = 'UA-xxxxx-3'
    url = '3.com'
    }

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', accountId]);
    _gaq.push(['_setDomainName', url]);
    _gaq.push(['_setAllowLinker', true]);
    _gaq.push(['_trackPageview', '/' + window.location.host + '/' + window.location.pathname]);

    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();

    </script>

  • #2
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    Most probably, the problem is that you are using the assignment instead of the equality operator.
    Quote Originally Posted by Julia11
    if($language == 'test') {
    if($brand == '1') {
    accountId = 'UA-xxxxx-1'
    url = '1.com'
    } else if ($brand == '2') {
    accountId = 'UA-xxxxx-2'
    url = '2.com'
    } else if ($brand == '3') {
    accountId = 'UA-xxxxx-3'
    url = '3.com'
    }
    I am still learning English


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •