Himanshu Yadav
Himanshu Yadav

Reputation: 13585

Why is Analytics Reporting Api data not matching with Google Analytics Dashboard?

I am working on an analytics module which pulls data from Google Analytics, Facebook and Twitter Analytics api.

Using Analytics Reporting Api V4 to pull the data from Google Analytics. Total number of sessions value does not match with what I see on Dashboard. I am using metric ga:sessions to pull the number of sessions.

In some cases, the number of sessions coming from reporting api matches with Dashboard. But not all the time. I am finding it hard to get it approved from QA without a proper explanation.

I checked dimension filters and reporting query multiple times but couldn't find anything wrong with it.

Added the samplingLevel to my report request but still seeing the same result.

ReportRequest totalNumberOfSessions = new ReportRequest().setViewId(VIEW_ID)
                .setDateRanges(Arrays.asList(lifetime))
                .setDimensions(Arrays.asList(custom))
                .setDimensionFilterClauses(Arrays.asList(clause))
                .setMetrics(Arrays.asList(sessions))
                .setSamplingLevel("LARGE");

Upvotes: 1

Views: 2719

Answers (1)

cnmuc
cnmuc

Reputation: 6145

According to https://developers.google.com/analytics/devguides/reporting/core/v4/samples, use setSegments instead of setDimensionFilterClauses. Like this:

    String path = "<your_path>";
    SegmentDimensionFilter exactPathDimensionFilter = new SegmentDimensionFilter()
            .setDimensionName("ga:pagePath").setOperator("EXACT")
            .setExpressions(Arrays.asList(path));
    SegmentFilterClause exactPathSegmentFilterClause = new SegmentFilterClause()
            .setDimensionFilter(exactPathDimensionFilter);
    OrFiltersForSegment orFiltersForSegment = new OrFiltersForSegment()
            .setSegmentFilterClauses(Arrays.asList(exactPathSegmentFilterClause));
    SimpleSegment simpleSegment = new SimpleSegment()
            .setOrFiltersForSegment(Arrays.asList(orFiltersForSegment));
    SegmentFilter segmentFilter = new SegmentFilter()
            .setSimpleSegment(simpleSegment);
    SegmentDefinition segmentDefinition = new SegmentDefinition()
            .setSegmentFilters(Arrays.asList(segmentFilter));
    DynamicSegment dynamicSegment = new DynamicSegment().setSessionSegment(
            segmentDefinition).setName("Path pageviews");
    Segment segment = new Segment().setDynamicSegment(dynamicSegment);

    ReportRequest request = new ReportRequest().setViewId(VIEW_ID)
            .setDateRanges(Arrays.asList(dateRange))
            .setMetrics(Arrays.asList(metric))
            .setDimensions(Arrays.asList(new Dimension().setName("ga:segment")))
            .setSegments(Arrays.asList(segment));

This example uses a path filter. You should change it according to your "clause" variable.

Upvotes: 1

Related Questions