Skip to content
Tips & tricks

Classify your data: Data import or GTM rules?

Do you want to sort your pages, downloaded documents or campaigns into readable categories for your reports? I'll show you 2 ways to get there (rules in GTM or the Data import CSV file) and when to prefer one or the other.

Alexis Neve 5 min read

The problem with raw data

GA4 records what your site sends it: a page address, a file name, a campaign name. However, these raw values are rarely readable in a report. They need to be sorted into meaningful categories, with a method suited to your volume and your needs.

2 methods can be used to write this classification:

  • Rules in Google Tag Manager (GTM): the value is calculated in the visitor's browser, at collection time.
  • GA4 Data import: the value is linked later, from a CSV file.

The typical classification case

Most of the time, it means classifying downloaded documents by type (manual, pricing, warranty), pages by section or campaigns by channel. At first, a few rules are enough, then exceptions arrive and the list grows.

Method 1: rules in GTM

GTM offers 2 main variables to write a classification.

RegEx Table

The RegEx Table variable compares an input variable (a URL, a file name, a click text) to a list of regular expressions, that is, expressions that recognise many spelling variants, which is what makes them useful. Each row links an expression to an output value. By default, the expression must match the whole string (Full Match option) and case is ignored. In addition, a default value covers the cases with no match and capture groups can be reused in the output ($1, $2).

The order of the rows sets the priorities: place the most specific rules first.

Lookup Table

The Lookup Table variable links an input value to an output value by exact match. It is easy to read back. However, it accepts no variants: a URL that differs by a single character is not recognised.

The limits common to both variables

  • The logic lives in the container. The rules are mixed in with tags and triggers, so a table of 200 rows becomes hard to read in the interface.
  • Every change requires a published version. Edit, preview mode, QA, publish: fixing a typo takes the same path as new tracking.
  • The calculation runs in the visitor's browser. The variable is evaluated on every event where it is used, so it weighs on the site, in a negligible way if the rules are few.
  • The value is frozen at collection. A faulty rule leaves wrong values in the data already collected.

Method 2: GA4 Data import with a CSV file

Data import (type Custom event data) replaces the rule with a mapping table: 1 CSV file, 1 row per key value. GA4 links the file to its data when the report is opened, so the history is reclassified too. It has other strengths:

  • The file can hold thousands of rows.
  • Nothing runs on the visitor's side and the GTM container stays light.
  • An update is just a new upload of the file, manual or scheduled by SFTP, with no version to publish.

In return, Data import has its limits:

  • A purely exact match. This means writing many rows before the import.
  • A delay. Imported data can take up to 24h to appear.
  • GA4 only. Other web analytics solutions (Piano, Adobe) and Ads or Meta tags do not see the file. The value is also unavailable in audiences and in exploration segments.

The same rule written both ways

The rule: classify a downloaded document by type. Pricing aimed at professionals (/pro/ folder) comes before general pricing.

In GTM, with a RegEx Table

Input variable: the click URL (built-in variable Click URL). Full Match enabled, hence the .* on both sides. Default value: Other.

OrderExpressionOutput
1.*/pro/.*pricing.*Professional pricing
2.*pricing.*Pricing
3.*(manual|guide).*Manual
4.*warranty.*Warranty

In Data import

A simple mapping table:

file_namedocument_type
pro-pricing-2024.pdfProfessional pricing
pricing-2024.pdfPricing
boiler_manual_v3.pdfManual
warranty-conditions.pdfWarranty

Priority becomes unnecessary, since each file has its own row.

GTM rules or Data import: the comparison

CriterionGTM rules (RegEx, Lookup)GA4 Data import
Type of conditionExpression or exact matchExact match on the key
Unknown valuesClassified by expression or by default(not set) until a row is added
Number of rulesA few dozenThousands of rows
UpdateGTM version to publishNew upload of the file
HistoryValue frozen at collectionAlso applied to past events
Value usable in GA4 audiences, BigQuery and Ads or Meta tagsYesNo, limited to GA4 reports and explorations
Who maintains itGTM profileMarketing or content team

How to choose between GTM and Data import

  • The number of rules. Up to a few dozen rules, a RegEx Table stays readable. Beyond that, the CSV file has the advantage.
  • Values never seen. An expression classifies new values, whereas a file requires one row per value.
  • How the value is used. A need to reclassify history points to Data import. A value wanted in audiences, in BigQuery or in Ads tags points to GTM.
  • The person who maintains it. A rule changed every week by the content team is better kept in a CSV. A stable rule, held by the person who manages the container, stays in GTM.

Finally, the 2 methods can be combined: GTM normalises the key (file name in lowercase, parameters removed) and Data import enriches it with titles, themes and needs.

Tools

  • Google Tag Manager: RegEx Table, Lookup Table, preview mode.
  • Google Analytics 4: Custom definitions, Data import, explorations.
  • Sheets or Excel: maintaining the CSV file.

Choosing where to house a classification rule is part of the tracking expertise.

Ready to take action?

Tell me about your site and your Ads platforms: you get a clear answer within 48 hours.

Get a quote