如何在没有 viewId 的情况下查询 Google Analytics

How to query Google Analytics without viewId

似乎 Universal Analytics 已被弃用,新版本的 Google 分析不提供 viewId?

有谁知道如何在没有 viewId 的情况下获取 google 分析数据?

  googleAuth.authenticate(authOptions, function (err, token) {
        axios.get(`https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A219265842&start-date=${startDate}&end-date=today&metrics=ga%3Ausers&dimensions=ga%3Acountry&access_token=${token}`)
            .then(analyticsData => {
              
                // res.json(analyticsData)
            })
            .catch(err => console.log(err))
    });

直到几周前,此代码仍在使用现有的 google 个具有 viewId 的分析帐户。

https://support.google.com/analytics/answer/2790010?hl=en

"Universal Analytics refers to the previous generation of Analytics. This was the default property type for websites prior to October 14, 2020."

遇到同样问题的人:

googleAuth.authenticate(authOptions, function (err, token) {
        var data = {
            "entity": {
                "propertyId": "YOUR_PROPERTY_ID"
            },
            "dateRanges": [
                {
                    "startDate": startDate,
                    "endDate": "today"
                }
            ],
            "dimensions": [
                {
                    "name": "deviceCategory"
                }
            ],
            "metrics": [
                {
                    "name": "totalUsers"
                }
            ]
        };

        var config = {
            method: 'post',
            url: `https://analyticsdata.googleapis.com/v1alpha:runReport?key=${keys.GOOGLE_API_KEY}`,
            headers: {
                'Authorization': `Bearer ${token}`,
                'Content-Type': 'text/plain'
            },
            data: data
        };

        axios(config)
.then(res=>{
console.log(res)
})
.catch(err=>console.log(err))

})