Solved

Events stack in the payload

  • 18 February 2022
  • 5 replies
  • 351 views

Badge +1

There is a website with Amplitude JS SDK installed. Hits are being sent to my custom server  and then redirected to the amplitude. To do so I’ve set ApiEndpoint parameter for init method. 

The thing is, when I fire a few events one by one, each hit contains data about the event it was fired by and all the previous events within current page load (if the page is reloaded it starts from the beginning again)

For example, I fire the first event “Click button”, payload contains only data about this event. Then I click one more time, so “Click button” fires again. In this case payload contains info about the first “Click button” and the previous click and so on. If there are 50 events, last payload would contains all of them.

 

What could be a cause of this issue?

 

icon

Best answer by Gnomemayrcy 22 March 2022, 12:19

View original

5 replies

Userlevel 6
Badge +8

Hi @Gnomemayrcy ! Welcome to the Amplitude Community and I’m happy to help :wave:

Can you clarify one thing for me? When you check the events in Amplitude, do you see that the events are duplicated? Or do you just see the 50 events only showing up once? I want to confirm whether you are actually seeing the data in Amplitude multiple times or if it just within the network requests. 

Also what network request are you looking at? From the screenshot, it doesn’t look like from api.amplitude.com? Do you use a proxy? 

Badge +1

Hi, thanks for the answer

 

do you see that the events are duplicated

Actually I’ve not check this in Amplitude because to send them all require some additional changes in my proxy server (Now I’m redirecting just the last event in stack) and I was sure that they would all be counted if I would redirect them all.

Also I know that Amplitude can save events in local storage in case of unsuccessful upload and then send them at once (here “saveEvent” parameter). Probably it somehow connected to it.

Also what network request are you looking at

Yes, it’s kind of proxy. I’m using  “ApiEndPoint” (https://amplitude.github.io/Amplitude-JavaScript/Options) parameter to send amplitude hits to server-side GTM and then I redirect those hits to my amplitude project via HTTP API.

Userlevel 6
Badge +8

Hi @Gnomemayrcy ! Got it - thank you for sharing that you use a specific set-up to send data to Amplitude! I do think that the behavior you are seeing is likely related to the save events in local storage feature as you have mentioned. Is there any chance you can try with a complete set-up (maybe to a test project) so that we can try and see whether a real-time stream would actually duplicate the events based on the payloads seen or the real-time stream actually only sends one unique event and it’s the save events feature that you are seeing? 

Badge +1

Hi again, sorry for the late answer. I’ve set up gtm the way I had mentioned and it works the way I expected: it does duplicate events in real-time view. For example, I trigger the first event and in real-time view I see it. Then I trigger the second event but in real-time view I see two new events (first and second), then three and so on.

Badge +1

I’ve solved it! The thing is, amplitude SDK is supposed to understand that a request is successful, and it does it by looking into response body. If there is a “success” string, then request is considered to be successful. If there is not, then sdk stores event info in local storage and resend it with the next event until it finds “success” in response body. 

So what I’ve done is set response body to “success” to every request I receive from the sdk and now It works fine.

Reply