Google Analytics App - Error 500

Enonic version: 6.4.0
OS: Ubuntu 15.10

Hi,

If I tick “Enable Tracking” the following error occurs when accessing the app. This error does not occur in “Preview mode”.

What it could be ?

Thx in advance.


It looks like headEnd is not an array and that’s why the “push” doesn’t work. It’s likely that some other application code uses page contributions with headEnd entered as a string. Make sure all uses of pageContributions are set up like you see below.

    var headEnd = res.pageContributions.headEnd;
    if (!headEnd) {
        res.pageContributions.headEnd = [];
    } else if(typeof headEnd == 'string') {
        res.pageContributions.headEnd = [ headEnd ];
    }
    res.pageContributions.headEnd.push(myCodeForHeadEnd);

Do not test with (headEnd instanceof String) because instanceof will only work word for “string literals” or strings created with new String("test"). http://stackoverflow.com/questions/203739/why-does-instanceof-return-false-for-some-literals

I think there is an error in The GA app. We’re fixing it :slight_smile:

Hi,

Please download the latest version (1.3.0) of the Google Analytics app that will fix this problem. Just go to Applications in your XP admin, open the Install dialog and click Update next to the GA app.

I can also recommend the lib-util on our Github and the data.forceArray() function as it does all that code for you and makes sure you can .push.

Spot on ase! This problem is fixed now. :sweat_smile:

Just one last question,

Is there any docs explaining how to fetch data from Google analytics ? In my case I need to retrieve the top 5 pages most accessed pages in one of the folder in our project.

I am studying the best way of doing this so I was wondering if there is any docs about that.

Thx.

You can find fairly good documentation on Google Analytics API here: https://developers.google.com/analytics/devguides/reporting/core/v3/ and some specific metrics here: https://developers.google.com/analytics/devguides/reporting/core/dimsmets.

However, in the case you mentioned I believe it would be rather difficult to succeed. Google Analytics stores data per site and per page, but not per folder. So you would have to write some aggregation code that would find all pages that belong to a folder, retrieve GA data for each of these pages, aggregated that data and then sort it. Not an easy task…

Good luck!

you are right! That’s going to take some effort. We left this part for later as we have some priorities to do first.

I let you know how we get on when we start. Thx! :+1: