All guides

Track custom events with Claude or your AI agent

Paste a prompt into your website coding agent to add an event your tracking does not detect automatically. Define the action, include available customer details and test the result.

Shahzada Ali Hassan

9 min read0 views

Illustration of a prompt sheet leading to a website form and then a single event tag.
View full size

Get clinic leads counting again

Recover usable Lead and Purchase events on your existing domain.

$297/mo per subdomain

Start 7-day trial

Payment method required. One trial per domain. Cancel during the 7-day trial.

Get a free consultation

The short answer

Paste the prompt below into Claude Code or the AI agent that edits your website. Describe the action you want to track; the agent inspects the code, asks only for missing details, and implements the event. It includes customer data and ecommerce objects when relevant. Use the checks below to confirm the website behavior and delivery to your selected platform.

For example: "Track a Lead in Meta after the contact form on /contact submits successfully." For a purchase, name the completed order or payment you want to count.

What prompt should I paste into Claude or my AI agent?

Copy this prompt into the project where your agent can edit the site, then describe your event. It contains the data structure and acceptance checks, so you do not need to write the tracking code yourself.

Check forwarding before relying on the result. The shared custom-event route checked on October 13, 2026 still needs customer-data and product-item forwarding confirmed by Crisper support. The agent can implement and test the website event; it should report any remaining delivery step.

Prompt for your website coding agent

Read the full prompt
Implement one website event in this project using its existing Crisper installation.

1. Inspect before editing
Find the requested action's handler, existing tracking and product/order data. Reuse a compatible helper and check whether this action is already tracked. Keep the change scoped to this event.

Ask only for missing answers:
- What action should count, and where does it happen?
- What name should appear, and in which ad/analytics platform?
- Which available customer or commerce fields are permitted to share?

Resolve ambiguity about the success condition or required data before implementing. Prefer generate_lead for a lead and the matching commerce action below. Keep an explicitly requested custom name after checking its platform mapping.

2. Emit this contract
Use the existing dataLayer and clear event-specific values before each push:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ user_data: null, ecommerce: null, properties: null });
window.dataLayer.push({
  event: "gtm_custom_event",
  datalayer_event_name: "<confirmed_event_name>",
  user_data: {},
  properties: {}
});

Replace the placeholder and empty objects with available, permitted values. Flat user_data keys are email, phone, first_name, last_name, street, city, region, zip, country and customer_id. Omit unknown fields; keep free-text form answers and sensitive labels out of event data. Preserve consent behavior. A form identifier can use properties.form.id.

Fire a lead only after accepted submission, capturing values before the form resets. For other actions, use the actual action/success signal. Prevent repeated handlers, renders, retries or page reloads from recounting the same completed action.

3. Add ecommerce only when relevant
Attach ecommerce beside user_data, not inside properties. Read actual product/cart/order values from the project:
- view_item: viewed product.
- add_to_cart: successfully added items and quantities, not the whole cart.
- begin_checkout: cart entering checkout.
- add_shipping_info / add_payment_info: completed checkout step.
- purchase: confirmed successful order and its final items.
A relevant custom commerce event can use this object too. Add only the requested action.

Purchase example with synthetic values; replace every value in the implementation:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ user_data: null, ecommerce: null, properties: null });
window.dataLayer.push({
  event: "gtm_custom_event",
  datalayer_event_name: "purchase",
  user_data: {},
  ecommerce: {
    transaction_id: "EXAMPLE_ORDER_1001",
    currency: "USD",
    value: 49.98,
    tax: 3.50,
    shipping: 5.00,
    items: [
      {
        item_id: "EXAMPLE_SKU_1",
        item_name: "Example product",
        price: 24.99,
        quantity: 2
      }
    ]
  },
  properties: {}
});

For commerce, send items with a stable item_id and/or permitted item_name, numeric discounted unit price and quantity. Include the actual three-letter currency whenever sending value. Value is the sum of price times quantity, excluding tax and shipping; send known tax/shipping separately. Convert minor-unit amounts correctly and avoid subtracting a discount twice. Include known, permitted brand/category/variant/coupon/discount fields only when supported. Omit ecommerce for a non-commerce action.

Purchase transaction_id must be the real, stable order ID. Preserve existing event-ID/deduplication behavior: a repeated order must not fire again, while a new order must still count. Report missing required data instead of inventing values.

4. Verify and report
Use local fixtures or test-mode checkout, with no real enquiry or charge. Test success, failure, repeated success/reload, a genuinely new action, and a commerce-to-lead transition with no stale fields. Check payload types, item quantities, currency and value arithmetic; run relevant project checks.

Verify the outgoing request and platform receipt when access permits, including user_data and ecommerce.items forwarding. If they cannot be verified, name the remaining check. Keep GTM containers, integrations, campaigns and payment settings unchanged; report a missing installation or forwarding configuration to the site owner/Crisper support instead of adding another sender.

Finish with the files changed, actual trigger and event names, a synthetic example payload, test results, and any unresolved setup step. Separate website implementation, platform delivery and ad attribution in your report.

What should the agent ask me?

Usually, the action and the name are enough to start. The agent should inspect the site for available customer, cart and order fields, then ask only about what remains unclear.

What action should count, and where?

Example answer
"A successful submission of the contact form on /contact."

What name should appear, and in which platform?

Example answer
"Lead in Meta Events Manager." The browser-to-platform mapping still needs checking.

Which available details are permitted to share?

Example answer
"Use the form's permitted email and phone fields. For purchases, include the confirmed order and its product data."

What does my AI agent need access to?

It needs your website project, permission to edit it and an installed Crisper tracking setup. Claude Code can read a codebase, edit files and run commands; an AI website builder can use this prompt where it has equivalent access. A chat-only assistant can suggest code for someone to install.

For a third-party form or checkout, the agent needs a documented completion signal rather than a guess about which button counts. The form and booking guide covers those signals. Connecting an agent to your Crisper account is separate; use the MCP guide for that setup.

What does the event structure mean?

Every event uses gtm_custom_event as its outer name. The action goes in datalayer_event_name. Google's data-layer documentation explains how the event message triggers tags and supplies their data.

event

Purpose
Always gtm_custom_event.

datalayer_event_name

Purpose
The browser action name, such as generate_lead or purchase. Check how the selected platform maps it.

user_data

Purpose
Known, permitted customer details. Use flat fields such as email, phone, first_name and last_name.

properties

Purpose
Relevant context, such as properties.form.id.

ecommerce

Purpose
Product/cart/order data when relevant, alongside user_data. Omit it from an ordinary lead.

A custom implementation can use a standard action name. Google recommends `generate_lead` for an enquiry. For another action, choose a clear name like demo_complete. If GA4 receives it, follow its naming rules: start with a letter, use letters, numbers and underscores, and check reserved names. Names are case sensitive; keep customer details and sensitive labels out of them.

Can the agent also add ecommerce objects?

Yes. The prompt includes a full purchase example and tells the agent to replace the synthetic values with actual product, cart or order data. Google's ecommerce guide describes when these shopping events apply.

Product viewed

Event and items
view_item: the viewed product.

Cart addition succeeds

Event and items
add_to_cart: only items and quantities added in that action.

Checkout begins

Event and items
begin_checkout: the cart entering checkout.

Order completes

Event and items
purchase: final order items and the stable transaction_id.

A relevant custom commerce action can carry ecommerce too. The agent should implement the action you asked for and check its integration mapping.

items

Value to use
An array of relevant products. Each has an item_id and/or permitted item_name, numeric unit price and quantity.

currency and value

Value to use
Actual three-letter currency and the sum of discounted item price times quantity. Keep amounts numeric, in major currency units.

transaction_id

Value to use
The real, stable order identifier for a purchase.

tax and shipping

Value to use
Separate numeric amounts when known. Exclude them from item value.

Optional details

Value to use
Known, permitted brand, category, variant, coupon or discount fields when supported.

In the illustrative prompt example, two units at 24.99 give a value of 49.98. Shipping of 5.00 and tax of 3.50 stay separate, as defined in Google's purchase reference. The reset before each event clears earlier order data; the stable order ID helps identify a repeated purchase.

How do I check that the event fires correctly?

Ask for the test results, not just a list of edited files. A successful lead or purchase should count once; a failed attempt should not count as that conversion.

  1. Complete the action with local fixtures or test-mode data. Check the event name, customer fields and any item quantities, currency and totals.
  2. Test failure, repeat the success callback and reload the confirmation page. Check that failure produces no conversion and the same success is not counted again.
  3. Complete a genuinely new action. Check that it still counts, and that a later lead/cart event does not inherit the previous order.
  4. Check the outgoing request and receipt in your selected platform, including the expected customer fields and items. Record any step that could not be checked.

The browser payload, platform delivery and ad attribution are separate results. The tracking verification guide explains what to check at each stage.

What if the event or its details still do not appear?

Locate the first missing step: the action's success signal, its data-layer event, the outgoing request or platform receipt. The generic custom-event tag in the shared web container checked on October 13, 2026 reads order totals but does not explicitly forward user_data or enable ecommerce-array forwarding. Give Crisper support the payload and missing fields so that route can be checked. Changing the website code does not configure the shared tag.

For a custom Meta event, also check Meta's review requirements. A data sharing restriction can limit its availability. The custom-event restriction guide covers that case.

For an installed Crisper site, use the prompt, review the website change through your normal release process, and keep its test results. Confirm delivery before relying on the new event for reporting.

If you still need Crisper installed, we recommend completing setup before adding custom events. Start 7-day trial, verify DNS, connect your integration and install the tracking snippets. Then implement and verify the action you need. A payment method is required, with one trial per domain and 7 days to cancel. 30-day money-back guarantee. We keep working with you until it is fixed.

Set up in about 5 minutes. Events in Events Manager within about 30.

~5 min setupwithin ~30 min
Setting up
  • 7-day free trialon every eligible domain, one per domain
  • $297/moper subdomain
  • We set up the first domain with youfounder included
  • 30-day money-back guaranteeand cancel any time in the trial
  • We keep working with youuntil it is fixed

Payment method required at checkout. One trial per domain. The 30 minutes start once tracking is installed and events fire; it is visibility in Events Manager, not same-day ROAS.