Google Analytics eCommerce: upload product data with Google Sheets

In this post, I will show you how to streamline your eCommerce tracking implementation and upload product data to Google Analytics.
From a remote CSV file.
Over Google Sheets.

Sounds good? Here we go!

TL;DR: I have a Github project to help you upload product data for Google Analytics Enhanced eCommerce via the API

Your Google Analytics eCommerce tracking is a temple

So you implemented Google Analytics Enhanced eCommerce tracking on your site? You charged up on product attributes? Everything looked great but you’re missing lots of data and/or transactions? I get this a lot from clients because their setup is far from perfect…

Many clients of mine saw GA’s EEC (Enhanced eCommerce) as a potential data smorgasbord, in which every single product attribute should be filled: tons of custom dimensions, custom metrics, extensive product categories – the works! Unfortunately, overloading your EEC tracking code with so much data tends to break tracking requests.
It is time to take better care of your EEC implementation!


The main culprit when it comes to GA EEC tracking failure is when the size of the tracking request exceeds the maximum allowed size.

If we consider how Google Analytics’ Measurement Protocol works, with all of its parameters, hits can fail if the requests get too big.

When the request size exceeds 8192 bytes (characters), the tracking request fails and traffic data does not get sent to Google Analytics servers.

How or why would you ever exceed that limitation?

So glad you asked!

Let’s assume you’re tracking a shopping cart containing 10 items. Each item contains a whole slew of attributes:

  • Product ID (SKU) and name
  • Category (w/ hierarchy)
  • Brand
  • Custom dimensions
  • Custom metrics
  • Product variant
  • Product price
  • And more!

Now imagine all the attributes are populated with sizeable values and labels and you can quickly reach 8192 characters, not including all the boilerplate Measurement Protocol parameters.

What can I do to fix it?

The first thing you can do is streamline tracking requests and only send the data you really need.

Stick to basics: only supply a product ID (SKU), quantity and unit price.

But what about all my attributes?

– You, shocked by such a minimalist approach

Fear not, we can use Google Analytics’ Data Import functionality to send those attributes! The goal here is to build a text file (comma-separated values, aka CSV) containing a common key (product ID/SKU) and related attributes. For instance:

1234Awesome WidgetWidgets
2345Super WidgetWidgets
3456Ultimate Widget Widgets

Once we have a CSV set up (manually or generated via PHP/Python/R/etc.) we can create a Data Import schema in Google Analytics.

Go to your administration panel, go to your property then go to Data Import.

Select Product Data
Name the import and select views where data will be processed
Map columns
Define overwrite settings

Mapping your columns provides you with a CSV schema with column headers you will need to follow.

Once you go through the steps, you’re all set! Now you can manually upload product data thanks to your CSV file.

Your Google Analytics Enhanced eCommerce reports now contain all the attributes contained in your CSV upload.

Every time Google Analytics sees a product ID, it will look in the import data and map provided values for product fields matching the product ID/SKU key. Amazing, right?

How often do I need to upload product data?

It boils down to how often new products appear/disappear in your catalog. If you add/remove products from your catalog on a daily basis then you need to upload your CSV on a daily basis. Unfortunately, unless you have strong publishing processes in place, you will tend to forget to upload said CSV and your reports will not contain the right product attributes 😐

Which is why I am offering a method to automatically upload your CSV file ad upload product data to Google Analytics. Of course you could use the Google Analytics Management API and code something with Python, Java or the language of your choice. Then you’d need to add scheduling in the form of a cron job.

With my method, I’m going to show you how to do it all in Google Sheets!

Create a blank Google Sheet

  1. Visit my Github repository
  2. Go to Tools > Script Editor
  3. Edit the file and use/adjust the code provided in this project to match your Google Analytics account / import settings

In the editor, go to Resources > Advanced Google services

In the list of services, scroll down to Google Analytics API and enable it

Testing your script

To test your script, simply select the uploadProductFeed function and click the “Play” button to the left of the drop-down menu. Go through the Google authentication dialog (you may need to use 2-factor authentication)

You also go to View > Execution transcript to look at console output

Go to your Google Analytics property and look for new uploads sent by the script via the API

Extra credit: scheduling uploads

Assuming your product feed is updated regularly, you can schedule your script to run on a regular basis. Thankfully, Google Sheets provides this scheduling for you.

  • From the script editor, click the “clock” icon or go to Edit > Current project’s triggers
  • If the trigger list is empty, click the blue button to create a new trigger
  • In the function dropdown menu, select your uploadProductFeed function
  • In event source, select Time-driven then select a frequency, e.g. Week timer and set it to run (for instance) every Monday at 8am
  • Save your trigger and enjoy your automatically updated product attributes in Google Analytics!

In closing

When it comes to working with data, it’s good to be lazy, erm, I mean to have efficient tools 😅

The method I describe in this post minimizes the risk if tracking hits failing because of data overload and ensures that I can upload product data via the Google Analytics API.

What about you? Have you set up data imports in Google Analytics? What went well? What went wrong? Let me know in the comments!

Author: Julien Coquet

Expert de la mesure d’audience sur Internet depuis plus de 15 ans, Julien Coquet est consultant senior digital analytics et responsable produit et évangélisation pour Hub’Scan, une solution d’assurance qualité du marquage analytics. > A propos de Julien Coquet

12 thoughts on “Google Analytics eCommerce: upload product data with Google Sheets”

  1. Hi Julien!

    Nice method. Very nice method!

    Just to be sure, is it retroactve or does it works only for new hits?

    Thanks in advanced for your answer!

  2. Is there really a great benefit to upload the file to avoid data overload, even if a product somehow has 20 attributes ? Seems like a lot dev effort to automate and synchronization of data.

    Is this recommended for a marketplace catalog or for small product catalogs ?

    1. Hi Ahmed and thanks for the feedback!

      Actually, in some cases, I had clients lose up to 30% of their transaction data because purchase hits were too big.

      CSV generation usually takes minutes using a Python/Java/PHP script and the upload process is automated by Sheets after you spend 10 minutes at most to follow the instructions in my post.
      I would say that’s time well spent for quality data, wouldn’t you?

  3. Hey Julien,

    Thanks for the detailed and well-explained article.

    It might sound stupid but just quick question, the primary key should not always be product sku right and can be any product level dimension ? Also, how soon do we start seeing product imported data (manually uploaded) start showing in reports

    1. Hi Mohammad,
      the goal is for you to replicate the data upload schema Google provides for each import.
      Data can take a bit of time to process and make sure to overwrite existing data with your upload

  4. Hi Julien, great post. I’ve been working for a long time with automated cost imports but I never thought of this use case, definitely will enrich my listings after this.

    Unfortunately, all my cost imports stopped working for no clear reason 2 days ago 🙁 !. I was wondering if it’s something related to the new GA version or some changes in the Management API. Did you face something similar with your data imports lately?


    Thanks a lot.

  5. Is there really a great benefit to upload the file to avoid data overload, even if a product somehow has 20 attributes ? Seems like a lot dev effort to automate and synchronization of data.

    Is this recommended for a marketplace catalog or for small product catalogs ?

    1. Hi Justin,
      i’ll take any solution that avoids data breakage and that’s one of them.
      The dev effort is low, frankly.

      The main criterion here is catalog data sophistication: the more attributes you have per item, the more you risk breaking data collection.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.