2017-08-01 72 views
1

我有一個節點應用程序。在這裏,我試圖使用Google API從谷歌分析中獲取推薦流。我已經提到了尺寸,指標和其他所需參數。這裏是我的代碼片段,如何使用谷歌分析API獲取推薦流程?

// imported googleapis npm module 
import google from "googleapis"; 
const analytics = google.analytics("v3"); 

// This is my payload to get the required analytics data 
const analyticsData = { 
    auth: oauth2Creds, 
    accountId: "accountID", 
    webPropertyId: "webPropertyID", 
    profileId: "profileID", 
    ids: "ga:id", 
    "start-date": "90daysAgo", 
    "end-date": "today", 
    metrics: "ga:pageValue,ga:pageviews,ga:entranceRate,ga:exitRate", 
    dimensions: "ga:fullReferrer", 
    "start-index": "1" 
}; 

// Function to get analytical data using the above payload 
analytics.data.ga.get(analyticsData, (err, result) => { 

    // I will get the results here 
    console.log(result); 

}); 

這裏它只返回與入口相關的數據。但我需要爲每次推介訪問獲取流量。例如,如果用戶從google進入主頁並轉到第2頁,第3頁並退出網站,那麼我需要跟蹤此流程。這如何使用谷歌分析API來完成?

回答