Skip to content

When firingTriggerId from json export is undefined, getTriggerNames will fail. #1

@andreseiji

Description

@andreseiji

Hey @rogersi9, nice code snippet! Saved me some time here to convert the GTM json export to a csv.

I used a json file without any changes exported from GTM, but for some reason there was at least one missing firingTriggerId, instead of an empty array, the export does no set the attribute, therefore throwing the following error on console:

index.js:26 Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')
    at getTriggerNames (index.js:26:9)
    at formatTag (index.js:36:24)
    at index.js:50:24
    at Array.forEach (<anonymous>)
    at gtmToCsv (index.js:49:12)
    at reader.onload (index.js:66:23)

As a quick fix, I change the getTriggerNames function to have an empty array for the ids param, as a default, it seems to have worked just fine:

function getTriggerNames(triggers, ids = [])

Opening the issue so if anyone runs into the same problem, maybe it helps.

Thanks again!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions