Javascript error in GA

Issue #15 resolved
massimo camporesi created an issue

When I display a GA report I don't see any mapped user and I find the following error in console: Uncaught TypeError: Cannot read property 'length' of undefined

Viewing the source code I've found that the variable 'MAPPING' is undefinded in the following code

if (typeof USERS !== 'undefined' && MAPPING.length > 0) { var i; for (i = 0; i < USERS.rows.length; i++) { if (USERS.rows[i][GAID] == userId + '') { // 2 equals here not three return USERS.rows[i][MAPPING]; } } }

Comments (5)

  1. Guillaume Loisel

    Hi Massimo, I had the same issue as you and have a fix for you until David can give a proper solution, it should work if you simply replace the searchForUser function to

    var searchForUser = function (userId) {
    
        var cMap = "";
    
        if(typeof MAPPING == 'undefined' && USERS.fields.length > 0) {
            for(var j = 0; j < USERS.fields.length; j++) {
                if(cMap == "" && USERS.fields[j] != GAID)
                    cMap = USERS.fields[j];
            }
        }
    
        if(cMap == "" && typeof MAPPING !== 'undefined') {
    
            if(MAPPING.length > 0)
                cMap = MAPPING;
    
        }
    
        if (typeof USERS !== 'undefined' && cMap != "") {
            var i;
            for (i = 0; i < USERS.rows.length; i++) {
                if (USERS.rows[i][GAID] == userId + '') { // 2 equals here not three
                    return USERS.rows[i][cMap];
                }
            }
        }
        return '';
    };
    

    Alternatively, you can just type in the field that you want to be used for the mapping, i.e. if you are using a csv file, the column that you would like to be shown below the user id. To do so, just change MAPPING in the following line to the name of the column (don't forget the quotes). return USERS.rows[i][MAPPING];

    There are still issues with this solution such as the popup not displaying on hovering the id, but if you are only using two fields (id and username like me for example) that should not be an issue.

    Let me know if this solution works for you.

    Thanks

  2. Log in to comment