google-analytics-api
보고 API (애널리틱스 v4)
수색…
비고
Google 애널리틱스보고 API V4 는 Google 애널리틱스의 보고서 데이터에 액세스하는 가장 진보 된 프로그래밍 방식입니다. Google 애널리틱스보고 API를 사용하면 다음 작업을 수행 할 수 있습니다.
- 맞춤 대시 보드를 만들어 Google 웹 로그 분석 데이터를 표시하십시오.
- 복잡한보고 작업을 자동화하여 시간을 절약하십시오.
- Google 애널리틱스 데이터를 다른 비즈니스 애플리케이션과 통합하십시오.
풍모
Google 웹 로그 분석 은 강력한 데이터보고 인프라를 기반으로합니다. Google 웹 로그 분석보고 API V4를 사용하면 Google 애널리틱스 플랫폼의 강력한 기능에 액세스 할 수 있습니다. API는 다음과 같은 주요 기능을 제공합니다.
- 메트릭 표현식 : API를 사용하면 내장 된 메트릭뿐만 아니라 수학 연산에서 표현 된 메트릭의 조합을 요청할 수 있습니다. 예를 들어 ga : goal1completions / ga : sessions라는 표현을 사용하여 세션 수별 목표 달성을 요청할 수 있습니다.
- 여러 날짜 범위 : API를 사용하면 단일 요청에서 두 날짜 범위의 데이터를 가져올 수 있습니다.
- 동질 집단 및 평생 가치 : API에는 동질 집단 및 평생 가치 보고서를 요청하는 풍부한 어휘가 있습니다.
- 다중 세그먼트 : API를 사용하면 단일 요청으로 여러 세그먼트를 가져올 수 있습니다.
Oauth2 C #을 사용한 단일 보고서 예제
이 예제는 공식 Google .net 클라이언트 라이브러리를 사용합니다.
권한 부여 다음 OAuth 범위 중 하나가 필요합니다.
Oauth2
// These are the scopes of permissions you need.
string[] scopes = new string[] { AnalyticsReportingService.Scope.AnalyticsReadonly }; // View your Google Analytics Data
UserCredential credential;
using (var stream = new FileStream(clientSecretJson, FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
// Requesting Authentication or loading previously stored authentication for userName
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
scopes,
userName,
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Reporting API service.
var service = new AnalyticsReportingService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = string.Format("{0} Authentication", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name),
});
보고 요청
// Create the DateRange object.
DateRange June2015 = new DateRange() { StartDate = "2015-01-01", EndDate = "2015-06-30" };
DateRange June2016 = new DateRange() { StartDate = "2016-01-01", EndDate = "2016-06-30" };
List<DateRange> dateRanges = new List<DateRange>() { June2016, June2015 };
// Create the ReportRequest object.
// This should have a large number of rows
ReportRequest reportRequest = new ReportRequest
{
ViewId = ConfigurationManager.AppSettings["GoogleAnaltyicsViewId"],
DateRanges = dateRanges,
Dimensions = new List<Dimension>() { new Dimension() { Name = "ga:date" }, new Dimension() { Name = "ga:usertype" } },
Metrics = new List<Metric>() { new Metric() { Expression= "ga:users" }, new Metric() { Expression = "ga:sessions" } },
PageSize = 1000,
};
List<ReportRequest> requests = new List<ReportRequest>();
requests.Add(reportRequest);
var getReport = new GetReportsRequest() { ReportRequests = requests };
var response = service.Reports.BatchGet(getReport).Execute();
단일 보고서 예제 나머지
API 요청은 API 끝점의 끝에 액세스 토큰이 첨부 된 HTTP POST입니다.
권한 부여 다음 OAuth 범위 중 하나가 필요합니다.
데이터를 게시 할 때 ContentType = "application/Json";
https://analyticsreporting.googleapis.com/v4/reports:batchGet?Access_token={from auth}
{
"reportRequests":[
{
"viewId":"XXXX",
"dateRanges":[
{
"startDate":"2015-06-15",
"endDate":"2015-06-30"
}],
"metrics":[
{
"expression":"ga:sessions"
}],
"dimensions": [
{
"name":"ga:browser"
}]
}]
}
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow