1
votes

Report

I have read this thread: Google Analytics API: Why is the API data different than what's being seen on the Analytics Dashboard? But still cannot figure out why my results differ so much from my Analytics Dashboard.

enter image description here

How can I check in .Net if my response contains sampleData? Here is the code I am using:

string[] s = new string[]{"https://www.googleapis.com/auth/analytics.readonly"};

var auth = GoogleAnalyticsServiceAccount.AuthenticateServiceAccount("XXXXX", "D:\\Spawtz\\Src\\client_id.json", s);

// Create the DateRange object.

//DateRange lastWeek = new DateRange() { StartDate = "2018-12-02", EndDate = "2018-12-09" };

DateRange lastMonth = new DateRange() { StartDate = "2018-11-09", EndDate = "2018-12-09" };

DateRange lastYear = new DateRange() { StartDate = "2017-12-09", EndDate = "2018-12-09" };

// Create the Metrics object.

Metric pageViews = new Metric { Expression = "ga:pageViews"};

//Create the Dimensions object.

Dimension pagePath = new Dimension { Name = "ga:pagePath" };

// Create the ReportRequest object.
// Create the ReportRequest object.

ReportRequest reportRequest = new ReportRequest

        {
            ViewId = "XXXXX",
            DateRanges = new List<DateRange>() { lastMonth, lastYear},
            Dimensions = new List<Dimension>() { pagePath },
            Metrics = new List<Metric>() { pageViews },
            FiltersExpression = "ga:pagePath==/cricket-player/t20/playerid=2348"

        };

List<ReportRequest> requests = new List<ReportRequest>();            
requests.Add(reportRequest);

// Create the GetReportsRequest object.

GetReportsRequest getReport = new GetReportsRequest() { ReportRequests = requests };

// Call the batchGet method.

GetReportsResponse response = auth.Reports.BatchGet(getReport).Execute();

Can I set the SamplingLevel and Max-Results in asp.Net?

1
Please take a picture of the numbers you are seeing in the dashbaord and then the results you are seeing from running your code. - DaImTo
Hi there, thanks for the reply. Here is the two images taken for same dateRange Value: ibb.co/QpQCBRw ibb.co/JRKf7sZ - Deon LastManStands
@DeonLastManStands - in your code you have /cricket-player/t20/playerid=2348 but in the screenshot it has /cricket-player/t20&playerid=2348 - could be skewing things? - scgough

1 Answers

0
votes

Yes you can set up the Sampling level for your report. It should be something like this Let me know if it doesnt work i can test it.

ReportRequest reportRequest = new ReportRequest
    {
        ViewId = "XXXXX",
        DateRanges = new List<DateRange>() { lastMonth, lastYear},
        Dimensions = new List<Dimension>() { pagePath },
        Metrics = new List<Metric>() { pageViews },

isDataGolden

The response data for each report should return a value called isDataGolden if the data is completed processing.

TIP

Remember that your request in the dashboard must be exactly the same as the request you are making to the API if you want the data to be the same. The exact same dimensions, metrics and dates. You cant look at a report in the dashbaord that contains five dimensions and then make a request to the api only looking at pageviews the numbers will not add up.

        FiltersExpression = "ga:pagePath==/cricket-player/t20/playerid=2348"
        Sampling = "SAMPLINGUNSPECIFIED"
    };

Update

According to the picture you posted you are looking at a report with the following dimensions and metrics.

  • page

  • pageviews

  • uniquepageviews
  • avg time on page
  • Entrances
  • bournce rate
  • % Exit
  • page value

Your request to the api must make the exact same request which means you need to use the exact same dimensions and metrics.