2016-05-01 64 views
1

Google Analytics API文檔顯示,爲獲取生命週期值,不應指定日期範圍。但是,當我提出這樣的請求(沒有日期範圍)時,它會返回空的維度和度量結果。但是,當我使用日期範圍時,它會返回該日期範圍的維度和指標值。從Google Analytics API獲取生命週期價值

下面是從API documentation的摘錄:

日期範圍應當不爲羣組或壽命值 請求來指定。

例如,如果我讓沒有日期範圍內的請求,如下所示:

{ 
"reportRequests": [ 
    { 
    "viewId": "XXXXXXXXX", 
    "dimensions": [ 
    { 
    "name": "ga:date" 
    }, 
    { 
    "name": "ga:eventLabel" 
    } 
    ], 
    "metrics": [ 
    { 
    "expression": "ga:totalEvents" 
    } 
    ] 
    } 
] 
} 

我得到以下響應:

{ 
"reports": [ 
    { 
    "columnHeader": { 
    "dimensions": [ 
    "ga:date", 
    "ga:eventLabel" 
    ], 
    "metricHeader": { 
    "metricHeaderEntries": [ 
     { 
     "name": "ga:totalEvents", 
     "type": "INTEGER" 
     } 
    ] 
    } 
    }, 
    "data": { 
    "totals": [ 
    { 
     "values": [ 
     "0" 
     ] 
    } 
    ] 
    } 
    } 
] 
} 

然而,如果我包括的時間範圍,

{ 
"reportRequests": [ 
    { 
    "viewId": "XXXXXXXX", 
    "dimensions": [ 
    { 
    "name": "ga:date" 
    }, 
    { 
    "name": "ga:eventLabel" 
    } 
    ], 
    "metrics": [ 
    { 
    "expression": "ga:totalEvents" 
    } 
    ], 
    "dateRanges": [ 
    { 
    "startDate": "2016-01-01", 
    "endDate": "2016-04-30" 
    } 
    ] 
    } 
] 
} 

我得到t他以下回應:

{ 
"reports": [ 
    { 
    "columnHeader": { 
    "dimensions": [ 
    "ga:date", 
    "ga:eventLabel" 
    ], 
    "metricHeader": { 
    "metricHeaderEntries": [ 
     { 
     "name": "ga:totalEvents", 
     "type": "INTEGER" 
     } 
    ] 
    } 
    }, 
    "data": { 
    "rows": [ 
    { 
     "dimensions": [ 
     "20160412", 
     "http://mytestblog.com/" 
     ], 
     "metrics": [ 
     { 
     "values": [ 
     "1" 
     ] 
     } 
     ] 
    }, 
    { 
     "dimensions": [ 
     "20160412", 
     "http://mytestblog.com/2016/04/first-post.html" 
     ], 
     "metrics": [ 
     { 
     "values": [ 
     "3" 
     ] 
     } 
     ] 
    }, 
    { 
     "dimensions": [ 
     "20160419", 
     "http://mytestblog.com/" 
     ], 
     "metrics": [ 
     { 
     "values": [ 
     "4" 
     ] 
     } 
     ] 
    }, 
    { 
     "dimensions": [ 
     "20160419", 
     "http://mytestblog.com/2016/04/fourth.html" 
     ], 
     "metrics": [ 
     { 
     "values": [ 
     "13" 
     ] 
     } 
     ] 
    } 
    ], 
    "totals": [ 
    { 
     "values": [ 
     "21" 
     ] 
    } 
    ], 
    "rowCount": 4, 
    "minimums": [ 
    { 
     "values": [ 
     "1" 
     ] 
    } 
    ], 
    "maximums": [ 
    { 
     "values": [ 
     "13" 
     ] 
    } 
    ] 
    } 
    } 
] 
} 

爲什麼說,儘管文件規定,我必須在指定的日期的ReportRequest範圍得到的值?我在這裏誤解了終身價值的含義嗎?

回答

0

對象reportRequest應具有dateRanges的值或cohortGroup的定義值。如果省略這兩個請求,則假定的startDateyesterdayendDate的默認值。

文檔的正確解釋是reportRequest應該沒有爲隊列和LTV請求定義的dateRange。但爲了制定隊列或生命週期價值請求,您必須添加隊列定義。終身價值的請求隊列定義應該有一個具體的dateRange除了lifetimeValue字段設置爲

POST https://analyticsreporting.googleapis.com/v4/reports:batchGet 
{ 
    "reportRequests": [ 
    { 
     "viewId": "XXXX", 
     "dimensions": [ 
      {"name": "ga:cohort" }, 
      {"name": "ga:cohortNthWeek" }], 
     "metrics": [ 
      {"expression": "ga:cohortTotalUsersWithLifetimeCriteria"}, 
      {"expression": "ga:cohortRevenuePerUser"} 
     ], 
     "cohortGroup": { 
      "cohorts": [{ 
       "name": "cohort 1", 
       "type": "FIRST_VISIT_DATE", 
       "dateRange": { 
        "startDate": "2015-08-01", 
        "endDate": "2015-09-01" 
       } 
      }, 
      { 
       "name": "cohort 2", 
       "type": "FIRST_VISIT_DATE", 
       "dateRange": { 
        "startDate": "2015-07-01", 
        "end_date": "2015-08-01" 
       } 
      }], 
      "lifetimeValue": True 
     } 
    }] 
    } 
+1

感謝您的評論@馬特。似乎有[Lifetime Value Report](https://support.google.com/analytics/answer/6182550)與CohortGroup分開。本報告僅適用於[應用程序視圖](https://support.google.com/analytics/answer/2649553#WebVersusAppViews)。此外,默認情況下,沒有指定日期範圍,它似乎是爲當前月份獲取數據(至少爲webview) – Kenpachi

+0

爲了澄清,爲了創建一個生命期值請求,您必須定義一個'cohortGroup'並設置'lifetimeValue'字段爲** True **。 – Matt