Search code examples
javascriptgoogle-analyticsanalytics.js

Is there a way to put Google Analytics for web into "dry run" mode like the GA mobile SDKs?


In Google Analytics mobile SDKs for both Android and iOS there is a flag you can set to put them into what's called "dry run" mode. Without changing any of your code, events won't be sent to Google when this is flipped on. Here's the documentation for the feature on Android and iOS.

This is really helpful for avoiding event tracking locally or in development and testing environments.

My question is whether there is any API in Google Analytics for web that works identically? I can't seem to find anything in the docs.


Solution

  • You can try and disable the sendHitTask or instead just log the hits to console? developers.google.com explains how to disable the sendHitTask.

    ga('set', 'sendHitTask', function (model) {
      console.log(model.get('hitPayload'));
    });
    

    You can also try and send the hits to validation server to get some basic validation result.