I want to read my website's Google Analytics data and render in admin panel.
Here is my codes:
const google = require('googleapis')
const scopes = 'https://www.googleapis.com/auth/analytics.readonly'
const jwt = new google.auth.JWT(process.env.GOOGLE_CLIENT_EMAIL, null, process.env.PRIVATE_KEY, scopes)
const view_id = '196847632'
async function getData() {
const response = await jwt.authorize()
const result = await google.analytics('v3').data.ga.get({
'auth': jwt,
'ids': 'ga:' + view_id,
'start-date': '30daysAgo',
'end-date': 'today',
'metrics': 'ga:pageviews'
})
}
But I'm getting this error:
const jwt = new google.auth.JWT(process.env.GOOGLE_CLIENT_EMAIL, null, process.env.PRIVATE_KEY, scopes)
TypeError: Cannot read property 'JWT' of undefined
How to solve this problem and get the Analtyics data to render to ejs file.