How to Make a Stacked Bar Chart in Google Analytics with AI

Cody Schneider••8 min read

A standard bar chart in Google Analytics is great for comparing numbers, such as sessions from each marketing channel. But what if you want to see the composition of each of those bars - for instance, how many sessions from each channel came from mobile versus desktop? For that, you need a stacked bar chart, a visualization that Google Analytics' standard reports don't offer out of the box. This article will show you how to get around that limitation and build the exact stacked bar charts you need, first using the old-fashioned way, and then with a much faster AI-powered approach.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

What a Stacked Bar Chart Can Reveal About Your GA4 Data

A stacked bar chart is a powerful visualization because it lets you compare totals across different categories while also seeing the breakdown of each category. It’s perfect for answering more nuanced questions about your website traffic and user behavior.

Imagine you want to see which marketing channels are driving the most traffic. A simple bar chart works fine. But with a stacked bar chart, you could ask:

  • "What is the breakdown of new vs. returning users for each channel?"
  • "Which countries contribute the most sessions within my top traffic sources?"
  • "How does mobile vs. desktop vs. tablet traffic look for each of my main landing pages?"

Each bar represents a primary dimension (like traffic channel), and the segments stacked within it represent a secondary dimension (like device type). This layered view helps you spot patterns you'd otherwise miss. For example, you might discover that your organic search traffic is almost entirely from mobile devices, while direct traffic is predominantly from desktop users. That’s an immediate, actionable insight for your content and UX strategies.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

The Old Way: Building a Stacked Bar Chart Manually

Since Google Analytics 4 doesn't have a direct option to create a stacked bar chart, the traditional workaround involves a manual and somewhat clunky process of exporting your data and building the chart in a spreadsheet program like Google Sheets or Excel.

While this method works, it's time-consuming and needs to be repeated every time you want to see updated data. Here’s a look at the typical steps involved.

Step 1: Export Your Data from GA4

First, you need to pull the raw data for your analysis. Let's say we want to build a chart showing Sessions by Session default channel group, segmented by Device category.

  1. Log into your GA4 property and go to Reports > Engagement > Pages and screens or any other detailed report.
  2. Click the pencil icon at the top right to customize the report.
  3. Under Report Data, click on Dimensions and set your primary dimension to "Session default channel group."
  4. Click Add dimension + and choose "Device category" as your secondary dimension.
  5. In the Metrics section, make sure "Sessions" is included.
  6. Click Apply and then Save the report.
  7. Once you have the report table on your screen, click the Share & Export icon (a box with an arrow) in the top right corner and choose Download CSV.

After a few moments, you'll have a CSV file with your data, ready for wrangling. The problem is, this report is static. The data is already old the moment you download it.

Step 2: Structure Your Data with a Pivot Table

The exported CSV file is in a "flat" format, meaning each row has a unique combination of your dimensions (e.g., one row for 'Organic Search - Desktop', another for 'Organic Search - Mobile', etc.). To create a stacked bar chart, you need to pivot this data so your primary dimension is on one axis, your secondary dimension becomes the column headers, and the metric values fill the table.

Here’s how to do that in Google Sheets:

  1. Open a new Google Sheet and go to File > Import > Upload to upload your CSV.
  2. Select all your data (including headers), then go to Insert > Pivot table and choose to create it on a new sheet.
  3. In the Pivot table editor on the right:

You’ll now have a neatly organized table with channels as rows, device types as columns (desktop, mobile, tablet), and the total sessions for each combination. This is the format required for charting.

Step 3: Create the Stacked Bar Chart

With your data properly structured, you can finally build the visualization.

  1. Select the data area of your pivot table, including the headers.
  2. Go to Insert > Chart.
  3. Google Sheets will probably suggest a chart type, but if it’s not what you want, use the Chart editor on the right.
  4. Under Setup > Chart type, scroll down to the "Bar" section and select the Stacked bar chart icon.

You did it! You now have a stacked bar chart visualization of your GA4 data. The process isn't incredibly complex, but it's tedious. And if your boss asks for an updated chart next Tuesday, or wants to see a different dimension, you have to start the entire process all over again.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

The Faster Way: Using AI to Build Your Chart in Seconds

The manual export-and-pivot routine highlights a key frustration for many marketers: getting to the insight can feel like navigating a maze of clicks, downloads, and spreadsheet formulas. AI-powered analytics tools eliminate this busy work entirely, letting you describe the chart you want in plain English.

This approach transforms a 20-minute, multi-step process into a 30-second conversation.

Step 1: Securely Connect Your Google Analytics Account

The first and only setup step is connecting your GA4 account to an AI analytics platform. Modern tools make this painless. Instead of hunting for API keys or complicated configurations, it's usually a simple authentication flow: you click a button, log in with your Google account, and grant permission. That's it. Your GA4 data is now ready for analysis without ever needing to export a CSV.

Step 2: Ask for Your Chart Using Natural Language

This is where the magic happens. Instead of navigating menus and building pivot tables, you just tell the AI what you want to see. Your request can be simple and conversational, just as if you were asking a human data analyst for help.

Using our previous example, you would simply type a prompt like:

Create a stacked bar chart of sessions by channel for the last 30 days, segmented by device category.

The AI understands the request. It knows what "sessions" and "channel" correspond to in the Google Analytics data schema (sessions and sessionDefaultChannelGroup). It recognizes "segmented by" as a command to create stacks and pulls the deviceCategory dimension automatically. Within seconds, it generates a clean, professional stacked bar chart based on your live GA4 data.

Here are a few other examples of what you could ask:

  • "Show my top 10 landing pages by user count this quarter, as a stacked bar chart broken down by new vs. returning users."
  • "Make a horizontal stacked bar chart comparing conversions by country for the past 90 days. Can you stack it by browser type?"
  • "I need a 100% stacked bar chart showing the percentage of traffic from mobile, desktop, and tablet for each social media source."

You don't need to know the official names of the GA4 dimensions or metrics. The AI parses your intent and builds the visualization for you.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Step 3: Iterate and Drill Down with Follow-Up Questions

The true power of AI analysis is its conversational nature. A chart isn't the end of your analysis, it's the beginning. New questions always emerge once you see the initial visualization, and with an AI tool, you can explore them instantly.

After generating your initial chart, you could ask follow-up questions like:

  • "Okay, filter this to only show traffic from the United States and Canada."
  • "Can you change this to last week's data?"
  • "What if we visualize this as a stacked column chart instead?"
  • "Hmm, can you remove 'tablet' from the view? I only care about mobile and desktop."

Each command modifies the existing chart in real-time. This turns data analysis into an interactive dialogue, allowing you to follow your curiosity and drill down into insights without ever leaving the reporting interface or touching another spreadsheet. What used to be a circular process of re-exporting and rebuilding charts is now a simple, exploratory conversation.

Final Thoughts

Stacked bar charts give a richer, more contextual view of your Google Analytics data than standard reports, but building them manually is a time-consuming chore. The multiple steps of exporting data, crafting pivot tables, and configuring charts in a spreadsheet are slow and don't scale well for teams who need fresh insights daily.

When we built Graphed, we wanted to eliminate that frustrating data-wrangling treadmill for good. Instead of forcing you through a rigid, manual process, you can connect your Google Analytics account in a few clicks and build the exact chart you need by simply asking for it in natural language. This means you can get right to the actionable insight in seconds, not hours, and answer follow-up questions on the fly, transforming your data from a static report into a dynamic conversation.

Related Articles