Meta · Track an eventStep 1 of 3

Track AddToCart

The AddToCart event fires when a visitor clicks the Add to Cart button on a product page. Meta uses this as a strong “buying intent” signal for retargeting and Smart Bidding.

Example of a product page with an Add to Cart button
AddToCart fires the moment the visitor clicks the button.

1. Find your Add-to-Cart button selector

Open a product page, right-click your Add to Cart button → Inspect. Note its id (e.g. add-to-cart-button) or a unique class (e.g. .btn-add-to-cart).

Browser DevTools showing the Add to Cart button HTML
If the button has no id, add one — or use a class with the . prefix.

2. Copy the snippet

Replace the example product info with template values that render the real product’s name, SKU, and price.

Option A — pbq (recommended)

product-page.html
<!-- Place inside the <body> of your product detail page,
     AFTER the AdsPing script in <head>. -->
<script>
  document.querySelector('#add-to-cart-button')
    .addEventListener('click', function () {
      pbq('track', 'AddToCart', {
        content_name: 'Acme Hydrating Serum',
        content_ids: ['SKU-1043'],
        content_type: 'product',
        value: 24.90,
        currency: 'USD'
      });
    });
</script>

Option B — dataLayer

product-page.html
<!-- Place inside the <body> of your product detail page,
     AFTER the AdsPing script in <head>. -->
<script>
  document.querySelector('#add-to-cart-button')
    .addEventListener('click', function () {
      window.dataLayer = window.dataLayer || [];
      window.dataLayer.push({
        event: 'add_to_cart',
        ecommerce: {
          value: 24.90,
          currency: 'USD',
          items: [
            { item_id: 'SKU-1043', item_name: 'Acme Hydrating Serum' }
          ]
        }
      });
    });
</script>

3. Where to paste it

Paste it inside the <body> of your product detail page template, near the bottom — so the button element exists in the DOM by the time the script attaches the click listener.

Code editor showing the AddToCart snippet pasted near the bottom of the product page body
Inside <body>, after the button HTML. Just before </body> is ideal.

4. Test it

Open a product page in your browser, click the Add to Cart button, then switch to your AdsPing dashboard. A AddToCart row appears in Recent Events within 10 seconds with a green Success badge.

AdsPing Recent Events showing an AddToCart event with a Success badge

✓ AddToCart is live.

Meta will start picking up cart additions as a buying-intent signal for retargeting and conversion optimization.