DumbData Code Solution For Deactivating "stg.timer" and "stg.leaveContent" Events In Piwik Pro

Here is the code you can insert above the Piwik Pro tracking script to attempt to disable the execution of the “stg.timer” and “stg.leaveContent” dataLayer events. It’s important to note that, on rare occasions, you might observe an initial triggering of these events before the deactivation takes effect. This does not indicate a malfunction; rather, it’s an occasional odd behaviour that can occur due to the way Piwik Pro’s code operates.

Should you have any questions or require assistance with Piwik Pro, please feel free to contact us via the DumBdata email at team@dumbdata.co.

				
					<script>
  // Step 1: Initialize dataLayer
  window.dataLayer = window.dataLayer || [];
  // step 2: is the code block for deactivating these Piwik Pro dataLayer events
	function initializeDeactivationScript() {
    // I wrapped the deactivation function in a another function for easy later reference
    (function() {
      var originalPush = window.dataLayer.push;
      window.dataLayer.push = function() {
        var args = Array.prototype.slice.call(arguments);
        var filteredArgs = args.filter(function(arg) {
          if (arg.event) {
            var deactivateEvents = ['stg.leaveContent', 'stg.timer'];
            if (deactivateEvents.indexOf(arg.event) !== -1) {
              console.log('Deactivated event:', arg.event);
              return false;
            }
          }
          return true;
        });
        if (filteredArgs.length > 0) {
          originalPush.apply(window.dataLayer, filteredArgs);
        }
      };
    })();
    // Your deactivation logic
    window.dataLayer.push({
      'event': 'deactivation_inplace'
    });
  }

  // Execute immediately
  initializeDeactivationScript();

  // Also execute on window load due to known weird behaviour
  	window.addEventListener('load', initializeDeactivationScript);

</script>

				
			

The code helps you move from this πŸ‘‡πŸΏ

To this, where the dataLayer events are now disabledπŸ‘‡πŸΏ

πŸš€ We've got more FREE measurement resources for you and your team😎 .

Before you leave, try out these free tools.
FREE GA4 AUDIT TOOL & UTM AUDIT TOOL