Clear Variables after request / Avoid automatic persistence of Custom Dimensions etc. into next Hit

Hi Lukas!

As of now it is not possible to clean all of the custom dimensions (CDs) on each hit/request with a single function. On the other hand, it is possible to get the list of used custom dimensions, iterate through the list and delete the values.

I have used setCustomRequestProcessing to catch the request and retrieve the query string before it’s sent.

Below you can find a WIP piece of code that represents what I’m talking about. Ideally, this should be triggered on each page view and prioritized before all tags.

<script>
  var _paq = _paq || [];
  function getDimensionIDArray(params) {
    var dimensionIDs = [];
    params.split("&").forEach(function(p) {
        if (p.includes("dimension")) {
            dimensionIDs.push(p.split('dimension').pop().split('=')[0]);
        }
    });
    return dimensionIDs;
  }
  _paq.push(['setCustomRequestProcessing', function(request) {
    var IDs = getDimensionIDArray(request);
  	IDs.forEach(function(id) {
      _paq.push(["deleteCustomDimension", id]);
    });
    return request;
  }])
</script>

Do let me know whether this solution is something you were looking for :).

1 Like