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/readable-stream@3.6.2/node_modules/readable-stream/lib/_stream_readable.js" and externals are not allowed![13:05:34] ERROR Cannot resolve "unenv/runtime/node/string_decoder/index/" from "/home/xxx/node_modules/.pnpm/readable-stream@3.6.2/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?