ASP.NET Google Reporting API的值不同于Google Analytics(分析)仪表板

时间:2018-12-10 08:13:19

标签: c# google-analytics google-api google-analytics-api google-api-dotnet-client

报告

我已阅读此线程:Google Analytics API: Why is the API data different than what's being seen on the Analytics Dashboard?,但仍然无法弄清为什么我的结果与我的Google Analytics(分析)仪表板有很大不同。

enter image description here

我如何在.Net中检查我的响应是否包含sampleData?这是我正在使用的代码:

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();

我可以在asp.Net中设置SamplingLevel和Max-Results吗?

1 个答案:

答案 0 :(得分:0)

是的,您可以为报告设置Sampling level。应该是这样的。让我知道它是否无效,我可以对其进行测试。

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

isDataGolden

如果完成处理,则每个报表的响应数据应返回一个称为isDataGolden的值。

提示

请记住,如果您希望数据相同,则仪表板中的请求必须与对API的请求完全相同。完全相同的尺寸,指标和日期。您不能在dashbaord中查看包含五个维度的报告,然后仅向该页面的浏览量请求api,而这些数字不会累加。

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

更新

根据您发布的图片,您正在查看具有以下维度和指标的报告。

  • 页面

  • 页面浏览量

  • 唯一页面浏览量
  • 页面平均停留时间
  • 入口
  • 出借率
  • 退出百分比
  • 页面价值

您对api的请求必须发出完全相同的请求,这意味着您需要使用完全相同的维度和指标。