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.
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.
- Open the ASP file (or the appropriate file for the server language you use) for your key event page.
- Find the ASP expression that stores that information. For example:
<%= orderId %>
. - Open the HTML for your key event page, and find your event snippet.
- 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
- Trigger the event on your website.
- In your web browser, view the source of the webpage. (In most browsers, right-click the page and select View source.)
- 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.