Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 2 of 2

Thread: Google Analytics: tracking under two different accounts

  1. #1
    zgarside is offline Junior Member
    Join Date
    Jun 2009
    Posts
    3

    Default Google Analytics: tracking under two different accounts

    I have two types of users on my site, and need to track them under separate Google accounts. I am using the JS code below to pick the tracking code to use. Alerting the variable "trackCode" on the final page shows it as UA-xxxxxxx-3, but all transactions come into Analytics as UA-xxxxxxx-1. Anyone doing anything like this?

    <script type="text/javascript">
    function getCookie(Name){
    var re=new RegExp(Name+"=[^;]+", "i");
    if (document.cookie.match(re)) {
    return document.cookie.match(re)[0].split("=")[1];
    } else {
    return "";
    }
    }
    try {
    var custLevel = getCookie("SFCustomerLevel");
    var trackCode = "";
    switch (custLevel) {
    case "D2":
    case "D1": trackCode = "UA-xxxxxxx-3";
    break;
    default: trackCode = "UA-xxxxxxx-1";
    break;
    }
    var pageTracker = _gat._getTracker(trackCode);
    pageTracker._trackPageview();
    } catch (err) {
    }
    </script>

  2. #2
    zgarside is offline Junior Member
    Join Date
    Jun 2009
    Posts
    3

    Default Figured this out

    In case anyone else needs this, follow the usual instructions for enabling Google Analytics, then set your Google.AnalyticsAccount AppConfig to "+trackCode+" (that's a double-quote, followed by a plus sign, a variable name, another plus sign and another double-quote). Then use Javascript to set that variable (in this case named trackCode) to valid Google Analytics id in the header of the page. In case you are wondering, the quotation marks on either side close out the quotation marks that get wrapped around your Analytics id when Storefront constructs the Analytics code, which results in two empty strings concatenated with the variable.