Google Analytics - fetching page view data from multiple pages

I’m trying to run a workflow that fetches the page view data from each page of a website and puts that data into a Cockpit collection so I can retrieve it as a HTML table.

For eaxmple, the pages: https:/ /mydomain . com?oc=12345 and https:/ /mydomain . com?oc=67890

I can run the workflow on each ‘oc’ value speratly and the workflow will put the data into the relevent Cockpit entry (the _id value is the same as the ‘oc’ value) - but I want to run the workflow on a schedule to update all of the pages/entries.

I have the following:

When it runs, the Google Analytics node fulls the data from ALL of the found pages with a result like:

It pulls in all of the page view data instead of seperating it into indivdual pages using the id’s from the previous node.

It then creates a HTML table with all that data and then updates the first ‘id’ in the Cockpit collection with that.

I thought the workflow would automatically loop through the page ids from the first node?

Can anyone point me in the direction as to where I’m going wrong!


Hi @seank1968,
nice to “meet” you in our community!

A couple of things you could try:

  • I suggest using the last version of n8n (if possible)
  • in “Dimensions to split by” add “Page” as the first dimension (this will also show you how the URLs are formatted)
  • in the “Dimension filters” use the ID you receive from the previous node and use it to filter the results from Analytics

Let me know if that helps and if you manage to make it work

Thanks @giulioandreini

This is the result of your worlflow - but it is the same as mine.

If I try using multiple ids for the imput I get the same results as before - all the data for each page is returned into one item and the html table created by the ‘Build HTML5’ node contains all of it which is then sent to the first ID’s Cockpit entry.

It doesn’t loop through each ID and only use the GA4 data from that page.

How do I get it to loop through the inputs? I was under the impression that N8N did this automatically?


Hi @seank1968 ,
could you share your updated workflow so I can test it on my side?

n8n is supposed to loop all the IDs in INPUT and use all of those to filter the results.
Check this screen from my local version and let me know if this is what you’re trying to accomplish:

In my case, I have 4 IDS coming in the INPUT panel, these are used to filter the pages (I had to use .toString() otherwise it was failing to match numbers and strings), and the results in OUTPUT are grouped by page URL and Country.

Hi @giulioandreini yes, that is working for the the Google Analytics node it’s returning data for all the page IDs - but what I need to do is then process each page IDs results (create a HTML table and update a Cockpit entry) individually. The workflow I posted takes ALL of the Google data, creates a single table and updates the entry using the first page ID. How do I get it to look through each page seperatly?


Hi @seank1968 ,
so you need o create an html table for each page?
What information do you want to display on those tables?
Hopefully with those info I’ll be able to help :wink:

By the way a couple of things worth checking out:

  • in the latest version of n8n you find an HTML Node that allows you to create some HTML structures and runs for each items that receives in the INPUT
  • also the new Code Node allows you to choose if you want to run it for each items (“Run Once for Each Item” select at the top)

Let me know if one of these two things help and the structure of the table you want to obtain


Hi @giulioandreini

Yes, thats right.
The table just needs the country and totalUsers data.

I’venot had time to look at the new nodes - but they do look useful!

Thanks agan!

Ok, glad to hear that helped.
If you need to build a table for each page you should definitely check the new HTML node,
an example here:


Hi @giulioandreini

I thought I had it working but it’s not quite there.

When the Google Analytics node runs it pulls in each county’s data into a seperate item - vthen the HTML node creates multiple tables with each item so there is only one line of data:

Can I get it to loop through the items and add them?

That HTML node is an excellent addition - I have a few workflows that generate an email at the end of the flow and it’s going to be much easier to create those with it!

Thanks again for your time!

Then if you want to have a single table with a row for each page you can do something like the example below.
In this case i first build the separate HTML rows in the HTML node, then merge them in the Code node, and inject them in an HTML table at once. This is just a way you can do it. You can get different configurations by combining the nodes HTML, Code, Items list.

Hi @giulioandreini that makes sense!

I’ve almost got it working! It’s creating individual tables for each page ID now - but it’s not matching the table to the correct ID:

In the image, IDs c7901783336463fd0c00004d and cb8bde7f63323081ac00010f are returning data (7 views and 69 views) as shown. The others are returning nothing as there are no views.

The HTML tables are being created - the first two for the above mentioned IDs:

But when I try and update the database fields it’s just using the page IDs in the order they were fetched in the original node:

So the first ID that returned no data is being sent the first table and so on.

How do I match the generated HTML table to the page ID that the Google data is for?


@seank1968 that is normal as the Google Analytics Node in this case sets its own order and subset of items that will hardy correspond to the original one in Get Profile IDs.

Question: is it possible for you to retrieve the ID back from the URL of the page? With some string manipulation?
In that case, you could use a Set Node as in the example below and have the HTML and related ID in the same item.

Hi @giulioandreini

I’ll have a look at that but for now I’ve used a Split In Batches node set to 1!

I also had to make sure the Google Analytics node settings were set to Always Output Data so it returned an emply response.

All seems to be working now!

Many thanks for your help on this

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.