Automate Matomo Analytics Insights with n8n and AI

Discover how to automate the retrieval and AI analysis of Matomo analytics data for visitors with more than 3 visits. This unique n8n workflow turns raw visitor data into actionable SEO insights, then stores the results in Baserow, saving hours of manual analysis each week.
httpRequest
code
baserow
+3
Workflow Identifier: 1808
NODES in Use: Manual Trigger, Schedule Trigger, HTTP Request, Code, Baserow, Sticky Note
Automate Matomo insights with n8n and AI

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow fetches data from Matomo Analytics for visitors who visited the site more than three times in the last 30 days.
It sends this data to an AI model that gives back insights about which pages are popular, common visitor paths, and user engagement patterns.
Finally, it saves those insights into a Baserow database, helping users get clear SEO advice without manual work.


Who should use this workflow

Users who manage websites and use Matomo Analytics but want to avoid manual exporting and analysis.
Digital marketers who want fast SEO insights from visitor data without extra work.


Tools / services used

  • Matomo Analytics: Source of visitor and page data.
  • OpenRouter AI (Meta LLaMA model): Processes visitor data into insights.
  • Baserow Database: Stores AI-generated insights for reporting.
  • n8n Automation Platform: Runs the workflow with triggers and nodes.

Inputs, processing steps, and output

Inputs

Processing steps

  • Retrieve recent visitor data with over three visits via Matomo API.
  • Format visitor actions into a clear text prompt.
  • Send prompt to AI chat model to get SEO and engagement analysis.
  • Receive AI response and prepare for storage.

Output

  • New record is created in Baserow database with analysis date, AI note, and website name.

Beginner step-by-step: How to use this workflow in n8n production

Import the workflow

  1. Download the workflow file using the Download button on this page.
  2. In n8n editor, click on Import from File and upload the downloaded file.

Configure credentials and IDs

  1. Add required credentials like Matomo API Key and OpenRouter API Key in n8n credentials manager.
  2. Update the HTTP Request node that fetches Matomo data with the correct site ID and token_auth.
  3. Check Baserow node and add your database ID, table ID, and API Key for access.
  4. Make sure any URLs or other IDs match your accounts.

Test and activate

  1. Run the workflow manually with Manual Trigger node to verify each step works.
  2. Check that the AI response is received and stored in Baserow correctly.
  3. Once confirmed, switch on the workflow toggle to activate the schedule trigger for weekly runs.
  4. Optionally explore this link for hosting n8n server yourself: self-host n8n.

How the workflow works

First, the Schedule Trigger or Manual Trigger starts the flow.

Then, an HTTP Request makes a POST call to Matomo API using your token_auth and site ID to get visitor data.

The retrieved visitor actions data is sent to a Code node which formats it into a readable prompt.

This prompt goes to the HTTP Request node calling OpenRouter AI, asking for SEO insights on pages visited and user behavior.

The AI answer is captured and sent to the Baserow node that adds an entry with the date, AI-generated note, and site name.


Code and prompt examples

The code node uses JavaScript to turn raw visitor JSON into a clear text prompt.

// Get input data
const items = $input.all();

// Format the visitor data into a clear prompt
const visitorData = items.map(item => {
  const visit = item.json;
  
  const visitorActions = visit.actionDetails.map(action => 
    `  - Page ${action.pageviewPosition}: ${action.pageTitle}\n    URL: ${action.url}\n    Time Spent: ${action.timeSpentPretty}`
  ).join('\n');

  return `- Visitor (ID: ${visit.visitorId}):\n  Visit Count: ${visit.visitCount}\n${visitorActions}`;
}).join('\n\n');

// Create the prompt
const prompt = `Please analyze this visitor data:\n\n${visitorData}\n\nPlease provide insights on:\n1. Common visitor paths\n2. Popular pages\n3. User engagement patterns\n4. Recommendations for improvement`;

// Return formatted for LLaMA
return [{
  json: {
    messages: [
      {
        role: "user",
        content: prompt
      }
    ]
  }
}];

The AI request body example sends a chat completion call to OpenRouter with a LLaMA model and user prompt.

= {
  "model": "meta-llama/llama-3.1-70b-instruct:free",
  "messages": [
    {
      "role": "user",
      "content": "You are an SEO expert. This is data of visitors who have visited my site more than 3 times and the pages they have visited. Can you give me insights into this data:${encodeURIComponent($json.messages[0].content)}"
    }
  ]
}

Customization ideas

  • Change visitor filter in HTTP Request (Matomo) by adjusting the “segment” parameter to capture different user groups.
  • Switch AI model or revise the prompt to target specific marketing questions by editing the AI request node.
  • Modify schedule frequency from weekly to daily or monthly in Schedule Trigger.
  • Add notification nodes like Gmail or Slack after Baserow to alert marketing teams when new insights arrive.
  • Expand the data saved in Baserow to include visitor counts or specific page URLs by mapping more fields.

Troubleshooting

  • Matomo HTTP Request fails: Check API URL and verify token_auth is correct and active.
  • Empty AI response or 401 errors: Confirm OpenRouter API Key is valid and the Authorization header is “Bearer <key>” with proper spacing.
  • Baserow node not storing data: Ensure correct database and table IDs are set and API key has proper write access.

Pre-production checklist

  • Verify all API keys for Matomo and OpenRouter are up-to-date.
  • Test Matomo HTTP node separately by running it manually.
  • Run code node on sample data to check prompt formation.
  • Test AI request node with a simple prompt.
  • Insert test record in Baserow manually to verify permissions.
  • Document all keys and endpoints safely for future troubleshooting.

Deployment

Switch on the workflow toggle to run on schedule.

Use Manual Trigger anytime to test.

Check logs in Execution History for success or errors.


Summary

✓ Saves hours by automating Matomo data fetching and analysis.
✓ Provides easy SEO insights from repeat visitor data.
✓ Automatically stores AI insights in central Baserow database.
✓ Runs weekly or on-demand inside n8n with minimal setup.
✓ Helps marketing teams act faster with clear engagement info.


Automate Matomo insights with n8n and AI

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

Yes. The user can replace the AI model in the OpenRouter request node with another compatible chat completion model.
Matomo API usage depends on the hosting setup. Usually, it is unlimited but the user should check their server limits.
Verify the OpenRouter API key is correct and the HTTP Header Authorization is set to ‘Bearer ‘ with a space after Bearer.
The Matomo HTTP Request node filters visitors using the ‘segment’ query parameter, such as ‘visitCount>3’ to get repeat visitors only.
Author
Written By
Ritu Sanjali

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.