Back to Integrations
integrationGmail node
integrationGoogle Analytics node

Gmail and Google Analytics integration

Save yourself the work of writing custom integrations for Gmail and Google Analytics and use n8n instead. Build adaptable and scalable Communication, and Analytics workflows that work with your technology stack. All within a building experience you will love.

How to connect Gmail and Google Analytics

  • Step 1: Create a new workflow
  • Step 2: Add and configure nodes
  • Step 3: Connect
  • Step 4: Customize and extend your integration
  • Step 5: Test and activate your workflow

Step 1: Create a new workflow and add the first step

In n8n, click the "Add workflow" button in the Workflows tab to create a new workflow. Add the starting point – a trigger on when your workflow should run: an app event, a schedule, a webhook call, another workflow, an AI chat, or a manual trigger. Sometimes, the HTTP Request node might already serve as your starting point.

Gmail and Google Analytics integration: Create a new workflow and add the first step

Step 2: Add and configure Gmail and Google Analytics nodes

You can find Gmail and Google Analytics in the nodes panel. Drag them onto your workflow canvas, selecting their actions. Click each node, choose a credential, and authenticate to grant n8n access. Configure Gmail and Google Analytics nodes one by one: input data on the left, parameters in the middle, and output data on the right.

Gmail and Google Analytics integration: Add and configure Gmail and Google Analytics nodes

Step 3: Connect Gmail and Google Analytics

A connection establishes a link between Gmail and Google Analytics (or vice versa) to route data through the workflow. Data flows from the output of one node to the input of another. You can have single or multiple connections for each node.

Gmail and Google Analytics integration: Connect Gmail and Google Analytics

Step 4: Customize and extend your Gmail and Google Analytics integration

Use n8n's core nodes such as If, Split Out, Merge, and others to transform and manipulate data. Write custom JavaScript or Python in the Code node and run it as a step in your workflow. Connect Gmail and Google Analytics with any of n8n’s 1000+ integrations, and incorporate advanced AI logic into your workflows.

Gmail and Google Analytics integration: Customize and extend your Gmail and Google Analytics integration

Step 5: Test and activate your Gmail and Google Analytics workflow

Save and run the workflow to see if everything works as expected. Based on your configuration, data should flow from Gmail to Google Analytics or vice versa. Easily debug your workflow: you can check past executions to isolate and fix the mistake. Once you've tested everything, make sure to save your workflow and activate it.

Gmail and Google Analytics integration: Test and activate your Gmail and Google Analytics workflow

Automate Google Analytics Reporting

Automate Google Analytics Reporting with n8n

This n8n workflow collects, processes, and formats Google Analytics data into a comprehensive HTML report. The report is segmented into three primary categories: Engagement Stats, Search Results, and Country Views. The formatted report can be emailed or saved as a document, and the workflow includes error handling and logging for better debugging.

Overview

Purpose

To automate the extraction, processing, and presentation of Google Analytics data in a visually appealing and structured format for easier insights and decision-making.

Features

  • Data Parsing: Individual parsers process raw Google Analytics data for different time periods and categories.
  • Data Aggregation: Combines parsed data into a single structured JSON object.
  • HTML Report Generation: Formats the aggregated data into an HTML table with color-coded segments for better readability.
  • Email or Document Output: The formatted report can be emailed or saved as a Google Doc (will need additional setup).
  • Error Handling: Includes checks for missing data and detailed error messages for debugging.

Workflow Steps

  1. Data Fetching:

    • Six separate Google Analytics data pulls:
      • Page Engagement Stats (This Week and Prior Week)
      • Google Search Results (This Week and Prior Week)
      • Country Views (This Week and Prior Week)
  2. Data Parsing:

    • Each data pull is processed using a dedicated parser node to generate a URL-safe string.
    • Example nodes:
      • Parse - Get Page Engagement This Week
      • Parse - Country Views Prior Week
  3. Data Aggregation:

    • Aggregates parsed data into a structured JSON object using the Aggregate Data node.
    • Ensures consistency and handles missing or malformed data.
  4. HTML Report Generation:

    • Creates a formatted HTML report with color-coded tables for each segment:
      • Engagement Stats: Green
      • Search Results: Blue
      • Country Views: Orange
    • Includes headers and neatly formatted tables for each data set.
  5. Output:

    • The report can be sent via email using the Gmail API or saved to Google Docs.
    • Example nodes:
      • Gmail node for email delivery.
      • Google Docs node for saving the report as a document.

Requirements

Prerequisites

  • Google Cloud Setup:
    • Enable Google Analytics API.
    • Enable Gmail API (if using email output).
    • Generate OAuth credentials for API access.
  • n8n Installation:

Environment Variables

  • Ensure API credentials and tokens are set up in the n8n environment.
  • Update the respective nodes with client ID, client secret, and access tokens.

Configuration

Google Analytics

  • Configure the Get Report nodes with the appropriate property ID and metrics.
  • Ensure correct date ranges are selected for each node.

Formatting Node

  • The Format Data node processes aggregated data and generates the HTML content.
  • Customize the HTML styling and segment colors as needed.

Email Node

  • Configure the Gmail node with OAuth credentials.
  • Set the recipient email address and subject line dynamically.

Error Handling

Common Issues

  1. Authentication Errors:

    • Ensure OAuth credentials are correct.
    • Verify that the APIs are enabled in the Google Cloud Console.
  2. Empty Data:

    • Check the raw data from Google Analytics.
    • Validate the property ID and query parameters in the Get Report nodes.
  3. Parsing Errors:

    • Ensure the parser nodes are correctly configured and match the expected input format.

Debugging

  • Use debug logs in each node to identify data flow issues.
  • Add error-handling nodes to capture and log issues during execution.

Example Usage

  1. Run the Workflow
    • Trigger the workflow to fetch, process, and format Google Analytics data.
  2. Verify Output
    • Check the formatted HTML output in the debug logs.
    • Ensure the email or Google Doc contains the correctly formatted report.

Future Enhancements

  • Add support for additional metrics or dimensions.
  • Integrate with Slack for notifications.
  • Enable scheduling for automated reports.
  • Add a visual dashboard for real-time analytics.

Nodes used in this workflow

Popular Gmail and Google Analytics workflows

Google Analytics node
Code node
+2

Automate Google Analytics Reporting

Automate Google Analytics Reporting with n8n This n8n workflow collects, processes, and formats Google Analytics data into a comprehensive HTML report. The report is segmented into three primary categories: Engagement Stats, Search Results, and Country Views. The formatted report can be emailed or saved as a document, and the workflow includes error handling and logging for better debugging. Overview Purpose To automate the extraction, processing, and presentation of Google Analytics data in a visually appealing and structured format for easier insights and decision-making. Features Data Parsing**: Individual parsers process raw Google Analytics data for different time periods and categories. Data Aggregation**: Combines parsed data into a single structured JSON object. HTML Report Generation**: Formats the aggregated data into an HTML table with color-coded segments for better readability. Email or Document Output**: The formatted report can be emailed or saved as a Google Doc (will need additional setup). Error Handling**: Includes checks for missing data and detailed error messages for debugging. Workflow Steps Data Fetching: Six separate Google Analytics data pulls: Page Engagement Stats (This Week and Prior Week) Google Search Results (This Week and Prior Week) Country Views (This Week and Prior Week) Data Parsing: Each data pull is processed using a dedicated parser node to generate a URL-safe string. Example nodes: Parse - Get Page Engagement This Week Parse - Country Views Prior Week Data Aggregation: Aggregates parsed data into a structured JSON object using the Aggregate Data node. Ensures consistency and handles missing or malformed data. HTML Report Generation: Creates a formatted HTML report with color-coded tables for each segment: Engagement Stats: Green Search Results: Blue Country Views: Orange Includes headers and neatly formatted tables for each data set. Output: The report can be sent via email using the Gmail API or saved to Google Docs. Example nodes: Gmail node for email delivery. Google Docs node for saving the report as a document. Requirements Prerequisites Google Cloud Setup**: Enable Google Analytics API. Enable Gmail API (if using email output). Generate OAuth credentials for API access. n8n Installation**: Self-hosted n8n instance with required nodes (Gmail, Google Docs, etc.). Free Cloud-based n8n account. Environment Variables Ensure API credentials and tokens are set up in the n8n environment. Update the respective nodes with client ID, client secret, and access tokens. Configuration Google Analytics Configure the Get Report nodes with the appropriate property ID and metrics. Ensure correct date ranges are selected for each node. Formatting Node The Format Data node processes aggregated data and generates the HTML content. Customize the HTML styling and segment colors as needed. Email Node Configure the Gmail node with OAuth credentials. Set the recipient email address and subject line dynamically. Error Handling Common Issues Authentication Errors: Ensure OAuth credentials are correct. Verify that the APIs are enabled in the Google Cloud Console. Empty Data: Check the raw data from Google Analytics. Validate the property ID and query parameters in the Get Report nodes. Parsing Errors: Ensure the parser nodes are correctly configured and match the expected input format. Debugging Use debug logs in each node to identify data flow issues. Add error-handling nodes to capture and log issues during execution. Example Usage Run the Workflow Trigger the workflow to fetch, process, and format Google Analytics data. Verify Output Check the formatted HTML output in the debug logs. Ensure the email or Google Doc contains the correctly formatted report. Future Enhancements Add support for additional metrics or dimensions. Integrate with Slack for notifications. Enable scheduling for automated reports. Add a visual dashboard for real-time analytics.

Build your own Gmail and Google Analytics integration

Create custom Gmail and Google Analytics workflows by choosing triggers and actions. Nodes come with global operations and settings, as well as app-specific parameters that can be configured. You can also use the HTTP Request node to query data from any app or service with a REST API.

Gmail supported actions

Add Label
Delete
Get
Get Many
Mark as Read
Mark as Unread
Remove Label
Reply
Send
Send and Wait for Approval
Create
Delete
Get
Get Many
Create
Delete
Get
Get Many
Add Label
Delete
Get
Get Many
Remove Label
Reply
Trash
Untrash

Google Analytics supported actions

Get
Return the analytics data
Search
Return user activity data

FAQs

  • Can Gmail connect with Google Analytics?

  • Can I use Gmail’s API with n8n?

  • Can I use Google Analytics’s API with n8n?

  • Is n8n secure for integrating Gmail and Google Analytics?

  • How to get started with Gmail and Google Analytics integration in n8n.io?

Looking to integrate Gmail and Google Analytics in your company?

Over 3000 companies switch to n8n every single week

Why use n8n to integrate Gmail with Google Analytics

Build complex workflows, really fast

Build complex workflows, really fast

Handle branching, merging and iteration easily.
Pause your workflow to wait for external events.

Code when you need it, UI when you don't

Simple debugging

Your data is displayed alongside your settings, making edge cases easy to track down.

Use templates to get started fast

Use 1000+ workflow templates available from our core team and our community.

Reuse your work

Copy and paste, easily import and export workflows.

Implement complex processes faster with n8n

red iconyellow iconred iconyellow icon