Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I clear (unset) custom dimensions from Google Analytics?

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.

like image 722
Niall Jackson Avatar asked Feb 03 '16 13:02

Niall Jackson


People also ask

How do I delete custom dimensions in Google Analytics?

Custom dimensions and metrics can't be deleted once created, but you can return to these settings in your account to manage and edit them. To stop using an existing custom dimension, uncheck the Active box, and click Save.

How do I delete a custom metric report in Google Analytics?

You can remove metrics by clicking on the “x” symbols next to them, or add metrics if space allows.

What is the difference between custom dimension and custom variable?

The name of a Custom Dimension can be changed at any time. Values of Custom Dimensions are limited to 255 characters whereas Custom Variables are limited to 200.


1 Answers

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.

like image 148
Niall Jackson Avatar answered Sep 19 '22 17:09

Niall Jackson