Looking for help with Google Analytics Data API (GA4 properties)

Hi.

I’m looking for help with Google Analytics Data API, having issue with the credentials.json file being used outside async run({ steps, $ }) so steps.trigger.context.attachments does not work.

Cheers.

Hey there, this is likely related to a known bug that we will be addressing soon. Here is the ticket that we’ll update when we fix it, if you’d like to follow along: [BUG] Workflow attachments aren't available in v2 Node.js code steps · Issue #2620 · PipedreamHQ/pipedream · GitHub

FYI I believe the issue is that attachments are not accessible to the workflow until after deploying, and even then, the UI will not surface attachments when trying to find it in steps.trigger.context (but you can still reference it after deploying, and it will work).

Thank you @droosevelt for your time and effort.

Actually, I can get the file but only inside async run({ steps, $ }) {} function. The problem is with the new GA4 API (Google Analytics Data API).
Maybe I’m way off, I’m not that big an expert on Google APIs, but I believe that your Google Analytics connector is not viable for GA4 and therefore I need to do authentication myself. This new GA4 API provides a JSON credentials file which must be declared as env.var, something like:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/credentials.json"

My guess is that this env.var is then read by node.js client library with

const {BetaAnalyticsDataClient} = require('@google-analytics/data');
const analyticsDataClient = new BetaAnalyticsDataClient();

The error message that I’m getting is saying that I’m missing credentials.json file because those two lines are at the top of the file, above async run({ steps, $ }) {} function, and therefore the node.js client library cannot get the attachment since it is provided only inside steps object.

Do you perhaps plan to release the new GA4 connector soon? That would resolve all the issues with the new Google Analytics Data API.

Again, thank you for your email, and please forgive me if my understanding of the problem is false.

Cheers.

You’re right that our Google Analytics integration does not yet support GA4 – this is on the backlog for us to support! We are tracking this here – feel free to follow along for updates.

And I’ve tagged engineering on the implementation question to get you unblocked in the interim.

Hi @sinisaperovic.

From the Google Cloud API docs, it looks like you can pass credentials explicitly in code rather than through an environment variable. For example:

const {BetaAnalyticsDataClient} = require('@google-analytics/data');

async run({ steps, $ }) {
  const keyFileame = steps.trigger.context.attachments["credentials.json"]
  const analyticsDataClient = new BetaAnalyticsDataClient({ keyFilename });

Here’s the doc in the source code for BetaAnalyticsDataClient.

Let me know if that works for you!

Thank you @droosevelt for your support.

Thank you @jacob-6562c7 for your time and effort, I really appreciate it. Apparently, I wasn’t paying enough attention to the details with BetaAnalyticsDataClient :frowning:

Cheers.

Just to let you know @jacob-6562c7 that after some tweaking of your idea, I managed to get an error saying 7 PERMISSION_DENIED: User does not have sufficient permissions for this property. which I’m guessing is progress :slight_smile:
Anyhow, analyticsDataClient should be initialized outside async run({ steps, $ }) {} or it won’t be defined, so I’ve created a function and I’m calling that function from within async run({ steps, $ }) {} passing keyFilename as an argument

Thank you again for your help.