DEV Community

Sherotree
Sherotree

Posted on

Require the agent to leave existing data-analytics attributes alone

The PR restyles a checkout button. It also removes data-analytics="checkout-submit" and renames data-cta="upgrade" to data-cta="upgrade-button" “to be clearer.” Nothing in the UI tests fails. A week later the funnel report is empty, because the collector still looks for the old names.

I’ve started treating analytics and experiment attributes as a contract, the same way I treat test IDs. A visual change is not a tracking-plan change. If the ticket is not about analytics, those attributes stay.

Why the attributes disappear

The model sees data-* hooks as optional decoration. It will “clean up” anything that is not a class or a handler, or it will rename them to match the new component name. Unlike a broken test id, a missing data-analytics attribute often has no CI check. The damage is delayed and silent.

Renames are as bad as deletions. Downstream dashboards, GTM triggers, and experiment buckets are not in the repo. Grep in the frontend will not find them.

A simple analytics-attribute policy

  • Existing data-analytics, data-cta, data-track, data-experiment, and similar hooks stay as they are
  • A rename or removal is its own PR, with an analytics owner in the review
  • New attributes are fine when the ticket adds a new event, using the existing naming scheme
  • Do not invent a second tracking prop (onTrack, a wrapper track()) when the hook already exists on the element

If the design system Button already forwards a trackingId or spreads data attributes, use that API. Do not drop the attribute because the new styled button “looks cleaner.”

What to put in the prompt

Do not remove or rename existing data-analytics, data-cta, data-track, or data-experiment attributes.
A visual or copy change is not a tracking-plan change.
If a new event is required, add a new attribute using the existing naming scheme, and mention it in the PR.
Do not invent a parallel tracking helper.
Enter fullscreen mode Exit fullscreen mode

In review, diff only the attribute lines: rg -n 'data-(analytics|cta|track|experiment|amp)'. Unexpected deletions or renames are a send-back, even if the screenshot looks right.

Reject / send back

Reject

  • A restyle that drops a tracking attribute
  • A “clearer” rename of an existing event name
  • A new trackClick() wrapper that replaces the attribute
  • Moving the attribute to a parent so the collector no longer sees the click target

Accept

  • A UI change that leaves the existing attributes untouched
  • A new attribute for a genuinely new event, documented in the PR
  • A dedicated analytics PR that updates the attribute and the tracking plan together

Top comments (0)