Disabling metric tracking during development

  • 31 March 2021
  • 7 replies


Just like the title, I’m wondering if there is any simple way to disable logging for few reasons

  • I’m developing a new feature for frontend and don’t want to send events that are created from interacting with the website
  • I’m running an automated E2E testing and don’t need to log events from the testing

Best answer by eddie.gaona 2 April 2021, 00:46

View original

7 replies

Userlevel 7
Badge +10

Hey @jakehong0521,

If it’s hard to disable event sending from your codebase while testing, you can try to block the events that are expected to get fired from your website interactions and unblock them later.

One of the best practices in this use case will be to create stage/dev environment project buckets in Amplitude ( if you haven’t already ) before any new feature release and test the features in there to ensure that you aren’t polluting your production environment with testing data. This ensures that events under development don’t affect the metric data in your production environment. 


Hope I have interpreted your use case correctly!


Thanks @Saish Redkar for answering the question!

I already set up the dev env and tweaked npm commends so that log data doesn’t get sent to prod project in Amplitude.

Manually setting events to block on Amplitude seems to be too much work because almost all types of events will get fired during E2E testing. Also, let’s consider a scenario where there are multiple frontend developers, each working on a different feature. Then, I can only image that blocking some events from one developer and unblocking other events from other developer and so on will cause complicated problems.

I’m wondering if there is any way to stop metric tracking at individual level by, for example, commenting out a piece of code or passing in empty API key (and without modifying dashboard setting).

Userlevel 5
Badge +9

Hello @jakehong0521!

From what I understand, when you are testing your website you do not want any events to be triggered to any Amplitude projects.

If I am understanding this correctly, simply passing in an empty API Key would prevent events from logging into Amplitude. I did the following and no events were triggered in Amplitude:


Let me know if I have understood your use case here!

Userlevel 7
Badge +10

Hey @jakehong0521 
Eddie’s solution could be the one you are looking for.

@eddie.gaona Can this approach be used if using the HTTP API without having to worry about 400s and 500s?


@eddie.gaona This is definitely the sort of answer I was looking for but I also really like what @Saish Redkar pointed out :) Would love to hear your answer to the question on 400/500s with what you proposed.

Userlevel 5
Badge +9

Great question @Saish Redkar !

It is the case @jakehong0521 @Saish Redkar that having the API KEY set to null in an HTTP API call will cause a 400 error. I tested the following call to test and it resulted in a 400 error with the issue being invalid API Key:

curl -H 'Content-Type: application/json' -d '{"api_key": "","events":[{"user_id":"4582375987", "event_type":"Check Event", "event_properties": {},"user_properties": {}}]}'



Hi everyone, I was able to set up the barebone of Amplitude this afternoon. Setting API key to be an empty string makes this error message show up in browser console. However, `logEvent` API doesn’t send any HTTP request is the API key is invalid so this is basically what I was looking for!