Creating list of items for JavaScript

Can anyone help me with this issue?

I’m using Google Analytics eCommerce tracking using dataLayer push via Google Tag Manager events.

Pushing a single item to the data layer using Javascript Toolbox is fine, but how can it do this for a number of items that make up an order. This works for a single item:

window.dataLayer = window.dataLayer || [];

An order can contain several items, but I want to be able to capture all the items in order, not just one.



Put you a for loop in there big dawg

1 Like

I don’t want to run the event multiple times, just add several items to the event, so begin_checkout only fires once, but I could have 1 item or 10 items and they’d all be captured as part of the event.

Hope I’m making sense, I’m a beginner at joining code like this to Bubble’s no code functions.

You most certainly will need a for loop

Can anyone help building the for loop? I’ve tried researching it but it’s beyond my current capability/ familiarity with JavaScript.

@doug.burden is right, you’ll need a for loop to process the list.

As for the code, you can do what i do. Ask ChatGPT for the code.

Or @ihsanzainal84, consult MDN and know the answer for yourself.