Can I send a selected event instantly if I enabled batch events when initiated Amplitude?

  • 5 October 2021
  • 1 reply

Hi, I am facing an issue where I want to be able to send a button click event instantly, but I have enabled sending batch events for my whole application.

I use the JS SDK to initiate like this

amplitudeClient.init('API_KEY', null, {
batchEvents: true,

With “batchEvents” enabled, events are batched together and uploaded only when the number of unsent events reaches a threshold or after a some seconds have passed since the first unsent event was logged.

In my landing page, there is a login button that redirects the user to another domain. I want to track the click event for that button before redirecting, so I log the event and then redirect the user in the callback, like this

amplitudeClient.logEvent('LOGIN_LINK_CLICK', {}, () => {
// Redirect the user to the login page

However, since we use “batchEvents”, this event is not sent immediately, so the user has to wait several seconds to be redirected. I want to know if I can send this event immediately, either by disabling “batchEvents” temporarily, or by using the HTTPv2 API, or any other method.


Thank you for your support


Best answer by Denis Holmes 6 October 2021, 10:45

View original

1 reply

Userlevel 4
Badge +2

Hi @vu.dao.unity ,


I see what you are trying to do. What you could do, is initialize a second instance of the SDK without batchEvents set to true and have that instance ready to send an event like this at a moments notice. 

The second solution would be to the event through the HTTP API V2 like you said, so that you can send it instantly. You would need to be sure to include all the relevant details in the payload of the JSON upload body. 

One of these should do just fine but I think the best bet would be to have the second instance of the SDK so that you can send it through that instantly, with batchEvents turned off. 


Hope this helps! Let me know if you need any more help!