A transaction ID is a unique identifier that you can create for each transaction, such as an order confirmation number. By adding a transaction ID to each ecommerce event, you can avoid counting duplicate conversions from the same user.
Conversion events are events that measure valuable actions on your site or app. You can measure any event as a conversion in Google Analytics. When someone completes a valuable action, a conversion should only be counted once. However, if a customer returns to a page or screen with a conversion event on it or reloads the page or screen, it's possible that the same conversion is registered twice, and the second load could be counted for the same order.
To avoid these duplicate conversions, you can edit your ecommerce events to capture a unique transaction ID, such as an order confirmation number you may already be using. If there are 2 conversions for the same conversion action with the same transaction ID, Google Analytics will know that the second conversion is a duplicate and the duplicate conversion won’t be counted.
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 conversion page.
- Find the ASP expression that stores that information. For example:
<%= orderId %>
. - Open the HTML for your conversion 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.