localhost:3000/api/analytics import it's not accepted? @google-analytics/data

[13:05:34] ERROR Cannot resolve "unenv/runtime/node/string_decoder/index/" from "/home/xxx/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_readable.js" and externals are not allowed! Localhost work's fine. But deploy for cloudflare pages didn't work:
import { BetaAnalyticsDataClient } from '@google-analytics/data'
import { ga } from '@/config/ganalytics.config'
export default defineEventHandler(async (event) => {
const propertyId = ga.property_id

const analyticsDataClient = new BetaAnalyticsDataClient({
credentials: {
client_email: ga.client_email,
private_key: ga.private_key?.replace(/\n/gm, '\n'), //
},
})
async function getServiceReport() {
const [response] = await analyticsDataClient.runReport({
property: `properties/${propertyId}`,
dateRanges: [
{
startDate: `7daysAgo`, //:point_left: e.g. "7daysAgo" or "30daysAgo"
endDate: 'today',
},
],
dimensions: [
{
name: 'fullPageUrl', // data will be year wise
},
],
metrics: [
{
name: 'screenPageViews', // it returs the active users
},
],
metricAggregations: ['TOTAL'],
})
return response
}
const data = await getServiceReport()
return {
hello: data,
}
})
import { BetaAnalyticsDataClient } from '@google-analytics/data'
import { ga } from '@/config/ganalytics.config'
export default defineEventHandler(async (event) => {
const propertyId = ga.property_id

const analyticsDataClient = new BetaAnalyticsDataClient({
credentials: {
client_email: ga.client_email,
private_key: ga.private_key?.replace(/\n/gm, '\n'), //
},
})
async function getServiceReport() {
const [response] = await analyticsDataClient.runReport({
property: `properties/${propertyId}`,
dateRanges: [
{
startDate: `7daysAgo`, //:point_left: e.g. "7daysAgo" or "30daysAgo"
endDate: 'today',
},
],
dimensions: [
{
name: 'fullPageUrl', // data will be year wise
},
],
metrics: [
{
name: 'screenPageViews', // it returs the active users
},
],
metricAggregations: ['TOTAL'],
})
return response
}
const data = await getServiceReport()
return {
hello: data,
}
})
What did I do wrong?
3 Replies
PaulG
PaulG3mo ago
Have you ever solved this issue?
Hermes Alves
Hermes AlvesOP3mo ago
Yes, with the new version it's working
PaulG
PaulG3mo ago
I use google vision package and it’s the same problem so I guess I’m stuck until they fix it 🥹
Want results from more Discord servers?
Add your server