Measure ecommerce

[GA4] Minimize duplicate key events with transaction IDs

A transaction ID is a unique identifier that you can create for each transaction, such as an order confirmation number. You must add a transaction ID (such as an order confirmation number)  to each ecommerce event to deduplicate transactions from the same user and to properly process refunds.

By adding a transaction ID, Google Analytics will deduplicate purchases if two purchases are registered with the same transaction ID.

Google Analytics only de-duplicates transactions with the same transaction ID from the same user. The same transaction ID can be used for different users without de-duplicating the transactions.

Note: Make sure you’re passing a dynamic value for the transaction ID. If your tag sends Google Analytics the same ID for different transactions, you could significantly undercount your key events.
Important: Do not send an empty string as the transaction ID. Google Analytics will deduplicate all purchase events that have transaction_id="".

Before you begin

The transaction ID must be unique for each order. For example, you could use the order confirmation numbers for your transactions.

The transaction IDs can include numbers, letters, and special characters like dashes or spaces. They must be unique for each transaction. The transaction IDs must omit any information that could be used to identify individual customers.

Add a transaction ID

You need to modify your code to collect the transaction ID. You don't need to make any changes in Google Analytics.

Note: Make sure you pass a dynamic value for the transaction ID. If you send the same ID for different transactions, then you could significantly undercount your conversions.

As an example, the following instructions use Active Server Pages (ASP) and update the gtag.js measurement code . The exact code will vary depending on the server language you use. Make sure to use the right language for your website.

  1. Open the ASP file (or the appropriate file for the server language you use) for your key event page.
  2. Find the ASP expression that stores that information. For example: <%= orderId %>.
  3. Open the HTML for your key event page, and find your event snippet.
  4. In the script section of the event snippet (between the <script></script> tags), replace <%= orderId %> with the ASP expression you found in step 2:

    Event snippet example:

        <script>
         gtag('event', 'purchase', {
          transaction_id: '<%= orderId %>',
          value: 25.42,
          currency: "USD",
          //...
         });
        </script>
    

Verify the transaction ID

  1. Trigger the event on your website.
  2. In your web browser, view the source of the webpage. (In most browsers, right-click the page and select View source.)
  3. You should see the measurement code between the <head> and </head> tags on your page. The ASP expression will be replaced by the actual transaction ID.

Was this helpful?

How can we improve it?
Search
Clear search
Close search
Google apps
Main menu
14794050899782540151
true
Search Help Center
true
true
true
true
true
69256
true
false