Google analytics reporting api for Node JS filter not returning category events

Viewed 96

I'm building a small Node JS cli and am using Google Analytics reporting, I have a bunch of events set up, my category is called "Fudge: Core", but when I attempt to use the filters I don't get any data back in rows, but removing the filters entirely I do see the data.

What am I missing?

#!/usr/bin/env node
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const dotenv = require('dotenv');
const env = dotenv.parse(fs.readFileSync(path.resolve(__dirname + '/../', `.env`)));
const Table = require('cli-table3');
const colors = require('colors');
const { google } = require('googleapis');
const dayjs = require('dayjs');

const startDate = dayjs().format('YYYY-MM-DD')
const endDate = dayjs().format('YYYY-MM-DD')

// Google scopes and credentials
const scopes = 'https://www.googleapis.com/auth/analytics.readonly'
const credentials = JSON.parse(env.GOOGLE_APPLICATION_CREDENTIALS)

// Google jwt
const jwt = new google.auth.JWT(credentials.client_email, null, credentials.private_key, scopes)

// Analytics view
const view_id = '257544393'

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': '2022-01-01',
    'end-date': endDate,
    'metrics': 'ga:uniqueEvents',
    'filters': 'ga:eventCategory=="Fudge: Core"', // <-- something wrong here?
    'dimensions': 'ga:eventCategory,ga:eventAction,ga:eventLabel'
  })

  console.dir(result.data.rows)
}

getData()
0 Answers
Related