Reputation: 261
On the "Thank You" page from an ecommerce transaction, I have used the Google Analytics tool to log the transaction. As part of this, I have used the 'set' feature to add some tracking data:
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': '123456',
'affiliation': '',
'revenue': '9.99',
'shipping': '1.11',
'tax': '0.00'
});
ga('set', {
'dimension5': 'Mr',
'dimension6': '1968',
'dimension7': 'G4'
});
ga('ecommerce:send');
This is all working fine. However, I have a search box on the sidebar of all pages, which I also track using Google Analytics. Normally this behaves perfectly, but if a user has just completed a transaction and uses the search box on that page, the custom dimensions are included in the details of that event.
How do I clear the custom dimensions completely? The API notes don't say, and the only reference I can find on a Google search recommends setting them to the empty string. This at least gets rid of the unwanted data, but the custom dimensions are still logged.
Upvotes: 10
Views: 3513
Reputation: 261
The correct way to get rid of them is to set the dimensions to null immediately after making the ecommerce:send call, like so:
...
ga('ecommerce:send');
ga('set', {
'dimension5': null,
'dimension6': null,
'dimension7': null
});
This will remove all reference to them from the 'collect' query string.
Upvotes: 11