0
votes

I am using Analytics Reporting v4 and Node.js.

I need to get a number of triggered events for a group of dimensions. For example:

  • dimensions: date, source, medium, campaign
  • metrics: pageviews, totalEvents
  • where eventAction = "Test Action"

When I combine these two metrics: pageviews and totalEvents, it shows the wrong numbers in result. But when I use them separately, then it works well.

True results for metrics:

  • total pageviews - 32 (but shows 17)
  • total events - 9

Maybe someone knows why? Maybe because it does not calculate pageviews where the user didn't do an action ("Test Action")? And how can I do this correctly?

Response example - http://i.imgur.com/BUkqiQG.png

Request code:

reportRequests: [{
    view_id: viewId,
    dateRanges: [{
        startDate: '2020-02-10',
        endDate: '2020-02-10',
    }],
    dimensions: [
        {
            name: 'ga:date'
        },
        {
            name: 'ga:source'
        },
        {
            name: 'ga:medium'
        },
        {
            name: 'ga:campaign'
        }
    ],
    metrics: [
        {
            expression: 'ga:pageviews'
        },
        {
            expression: 'ga:totalEvents'
        },
    ],
    orderBys: [{
        fieldName: 'ga:date',
        sortOrder: "ASCENDING"
    }],
    dimensionFilterClauses: [{
        filters: [
            {
                dimension_name: 'ga:eventAction',
                operator: 'EXACT',
                expressions: ["Test Action"]
            }
        ]
    }]
}]
1

1 Answers

0
votes

This is because you are filtering down the pages to those which only have the event.

The source, medium, campaign dimensions are all session level. Therefore, when you report on those, and just pageviews, they give total pageviews.

However, when you filter the results to where eventAction=Test, it only returns the pageviews where that event action occurred.

Instead of this, I would suggest using a segment, something like:

"segments": [{
"dynamicSegment": {
    "sessionSegment": {
        "segmentFilters": [{
          "simpleSegment" :{
            "orFiltersForSegment": [{
              "segmentFilterClauses":[{
                "dimensionFilter": {
                  "dimensionName": "ga:eventAction",
                  "expressions": ["Test Action"]
                }
              }]
            }]
          }
        }]
      }
    }
}]

More info: https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet#DynamicSegment