Why Does "TypeError: Cannot read properties of undefined (reading …)” Occur in My "Parse GA4 Response" Action Code?

This topic was automatically generated from Slack. You can find the original thread here.

Is anyone else getting a “TypeError: Cannot read properties of undefined (reading …)” unexpectedly?

Here is my action code that is causing this issue:

export default {
    name: "Parse GA4 Response",
    key: "parse_ga4_response",
    description: "Returns a JSON object for a Google Analytics 4 response.",
    version: "0.0.5",
    type: "action",
    props: {},  
    
    async run({ steps, $ }) {
      const metrics = steps.ga4_report.$return_value;
      // more code goes here
    }
}

I did run the previous step, which loads ga4_report into steps correctly. If I comment out key: "parse_ga4_response" then everything executes as expected. Otherwise, I can’t seem to get this error to disappear.

Hi Steve, sorry for the confusion but steps are not available in custom actions.

This is because step names can vary from workflow to workflow.

Instead use props to pass data into custom actions. That will decouple the source of the data across workflows.

can you explain why steps are not available in custom actions?

steps are not available in custom actions because they contain the workflow step exports, which can vary from workflow to workflow. When you publish a custom action, it becomes reusable across many workflows, and the step exports available depend on the specific workflow it’s running on. Instead of using steps, you should use props to pass data into custom actions, which allows individual workflows to define which exports should be used and decouples the source of the data across workflows.

Ah, that makes sense. I’ll switch to using props, which was on my todo list. Thanks !

Sure thing :slightly_smiling_face: