SEO + AEO on AutopilotFrom the team at Stackmatix
The Growth Library

Unnest GA4 Parameters Without Multiplying Content Events

Extract GA4 repeated parameters with count checks that catch array multiplication, missing-value loss, and ambiguous keys before reporting content use.

Approve a GA4 export query only after proving which rows it counts. Unnesting repeated arrays can multiply one event into several rows, and inner joins can remove events whose optional arrays are empty. Preserve event-level identity in a synthetic fixture before trusting a content breakdown.

The practical artifact is an input-and-output contract: event rows in, extracted values and ambiguity states out, and a reconciliation at the intended grain. This is not a new export setup or a request for additional visitor data.

Declare The Output Grain First

Decide whether the report needs one row per event, one row per item, or another defined unit. Flattening an items array can be correct for item analysis and wrong for counting resource events. The same SQL shape is not appropriate for every question.

Google's GA4 schema documents repeated event parameters and item structures. Inspect the actual field types and available identifiers rather than assuming every event contains a populated item list.

The transfer-validation guide checks replay and source snapshot grain. This procedure concerns multiplication inside one nested event record, which is a different source of inflated counts.

Understand What Unnest Produces

The BigQuery array guidance explains that UNNEST returns a row for each array element. It also notes that inner flattening excludes empty or null arrays and shows left-join treatment where retaining such source rows is intended.

Joining two independent arrays can produce combinations of their elements. Do not assume that a parameter row and an item row have a meaningful one-to-one relationship simply because they came from the same event.

A left join can preserve the parent row but does not automatically restore one-row-per-event grain. Multiple elements can still multiply it. Choose an extraction or aggregation shape that matches the declared output.

Use A Synthetic Three-Event Fixture

Consider three invented event records. Event E1 has two parameters and three items. E2 has two parameters and two items. E3 has empty arrays. The artificial fixture IDs below are local test labels, not a claim that GA4 supplies a universal event_id field.

An unsafe cross join over both arrays produces six rows for E1, four for E2, and none for E3: ten rows from three events. Counting those rows as ten content events would be wrong.

E2 deliberately has two different values for the same content key. An extraction that silently takes the first or an arbitrary value hides that ambiguity. E3 should remain present with a missing state if the output contract is event-level.

Execute A Small Reference Test

The following Python fixture tests expected cardinality and extraction states locally. It models the nested-row problem; it is not a query executed against BigQuery or a reconstruction of real visitors.

events = [
    {"id": "E1", "params": [("content", "guide-a"), ("topic", "import")], "items": [1, 2, 3]},
    {"id": "E2", "params": [("content", "guide-b"), ("content", "guide-c")], "items": [1, 2]},
    {"id": "E3", "params": [], "items": []},
]
unsafe_rows = sum(len(e["params"]) * len(e["items"]) for e in events)
assert unsafe_rows == 10
output = []
for event in events:
    values = [v for k, v in event["params"] if k == "content"]
    state = "valid" if len(values) == 1 else "missing" if not values else "ambiguous"
    output.append((event["id"], values[0] if state == "valid" else None, state))
assert output == [("E1", "guide-a", "valid"), ("E2", None, "ambiguous"), ("E3", None, "missing")]
assert len(output) == len(events) == 3

The contract intentionally treats repeated keys as ambiguous even if a later policy might allow a specific resolution. Define such a policy explicitly before changing the fixture. Do not let a convenient aggregate choose the business meaning.

Translate The Contract Into The Actual Query

For event-level reporting, consider extracting an optional parameter through a correlated expression or another supported shape that retains the parent event. Count matching keys and inspect the value type rather than assuming every parameter is a string.

If the actual task needs item rows, unnest deliberately and label the output unit. Aggregate back to the intended event level only with a valid grouping method. A convenient timestamp or an invented concatenation is not automatically a unique event key.

Use permitted staging data and the warehouse owner's reviewed query process. This article does not authorize running expensive queries, enabling exports, or accessing production identifiers. Keep byte-scan and access decisions with the responsible owner.

Test Missing And Unexpected Values

Include an absent key, a duplicate key, an empty array, an unexpected value type, and an event type that does not use the parameter. Decide whether each is valid, missing, ambiguous, or outside the report's scope.

Do not replace every missing value with zero or the most common resource. For a content label, that can fabricate readership for a guide. The measurement-gap framework provides a useful explicit unknown state.

If an event is intentionally excluded, preserve the count and reason in the reconciliation. Dropping E3 may be appropriate for a report requiring a content identifier, but it changes the eligible population and must not remain invisible.

Reconcile Before Looking At Rates

Record input events, output rows, valid extracted values, ambiguous values, missing values, and excluded events. In this fixture, one valid plus one ambiguous plus one missing equals the original three events.

A ratio can look plausible after multiplication because both numerator and denominator changed. Check independent counts and value sums, not only the final rate. The worked-example guide helps keep those units visible.

Test the query's expected failure too. A deliberate independent-array cross join should fail the event-level row-count assertion. A test that merely confirms the query returns some rows cannot protect the report.

Keep Reporting Scope Distinct From Collection Completeness

A correctly shaped query counts the available eligible export records under its contract. It does not prove that every reader was collected or that its totals must equal every GA4 interface report.

The click/session reconciliation illustrates why different systems and metrics can disagree. Do not force equality by changing the extraction until a desired dashboard total appears.

Approve A Reusable Cardinality Receipt

Save the schema reference, output grain, synthetic fixture, expected states, executed local assertions, actual query revision, and source-count reconciliation where authorized. Keep a different analyst's review of the duplicate and empty-array cases.

Approve the analysis when nested extraction preserves the declared unit and ambiguity remains visible. That gives content reporting a trustworthy foundation without mistaking array elements for additional readers or events.

Sources

Matt Pru

Co-founder and CEO of Stackmatix. Writing about growth, customer acquisition, and the decisions behind useful marketing. Connect on LinkedIn.

Developed with AI assistance under Matt's editorial direction. Our Editorial Approach