Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplitude Logger [Error]: Failed to fetch #579

Open
Decolo opened this issue Sep 12, 2023 · 12 comments
Open

Amplitude Logger [Error]: Failed to fetch #579

Decolo opened this issue Sep 12, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@Decolo
Copy link

Decolo commented Sep 12, 2023

Expected Behavior

expect that no response error when sending event to amplitude

Current Behavior

image I found some issue on sentry. This kind of issue happened accidentally.

All of this new user's events can't be found on the amplitude platform. So I use sentry to sending event simultaneously, this user can be found on sentry..

Possible Solution

I guess our amplitude setting up is not the best practise, especially the userId setup.
I have posted a topic before https://community.amplitude.com/data-instrumentation-57/amplitude-logger-error-load-failed-2765. And then I follow the example of nextjs to adjust:

// before
amplitude.setUserId(data?.data?.result?.userId);

// now 
amplitude.identify(new amplitude.Identify().set("JR_userId", data?.data?.result?.userId));

The previous error is: Amplitude Logger [Error]: Load failed
The current error is: Amplitude Logger [Error]: Failed to fetch

Steps to Reproduce

  1. init amplitude in _app.page.tsx
if (typeof window !== "undefined") {
  amplitude.init(AMPLITUDE_API_KEY);
}
  1. set userId in user.properties by amplitude.identify(new amplitude.Identify().set();
// our backend will generate a userId.
// after get userId in client, I will set it by Identify

if (data?.data?.result?.userId) {
        // https://github.com/amplitude/Amplitude-TypeScript/blob/main/examples/browser/next-app/pages/index.tsx
        amplitude.identify(new amplitude.Identify().set("JR_userId", data?.data?.result?.userId));
      }
  1. send event by amplitude.track
amplitude.track(eventInput, {
    ...eventProperties,
  });

Environment

  • JS SDK Version: 2.2.3
  • Installation Method: pnpm
  • Browser and Version: [Chrome 116.0.0]
@Decolo Decolo added the bug Something isn't working label Sep 12, 2023
@yuhao900914
Copy link
Contributor

Hi @Decolo , thanks for using Amplitude.
amplitude browser only supports the client side. Using amplitude browser SDK on server-side might cause an issue. can you make sure if that's the case?

@Decolo
Copy link
Author

Decolo commented Sep 13, 2023

Hi, @yuhao900914, thx for replying.

This is the codes in our nextjs project, I checked the existence of window object firstly (server-side no window object) to ensure amplitude.init() in client-side.

// _app.page.tsx

if (window) {
  amplitude.init(AMPLITUDE_API_KEY);
}

Now I change some options when amplitude.init(), seems no more Amplitude Logger [Error]: Failed to fetch error yesterday, but still need more time to verify.

if (typeof window !== "undefined") {
  amplitude.init(AMPLITUDE_API_KEY, {
    defaultTracking: true,
    transport: "xhr",
  });
}

And I want to find the root cause of this, maybe it's a response error? But the message of error is a little unclear.

image

@yuhao900914
Copy link
Contributor

We have an example app in GitHub here. It's working fine.
In steps 2 and 3 did you check if there is an amplitude instance before calling the identify and track call?

Did you try to enable the debug mode and check if there is any valuable info there?

Do you have a website link/example app where we can test it out?

@Decolo
Copy link
Author

Decolo commented Sep 14, 2023

@yuhao900914 thx, Alyssa.
What you mentioned:

  1. How to check amplitude instance, like codes below?
if (amplitude) {
  amplitude.identify(new amplitude.Identify().set("userid", data?.data?.result?.userId));
}
  1. I'll try the debug mode later
  2. Today we met a new issue
    image
    image
    seems sdk get an exception response from server?

@yuhao900914
Copy link
Contributor

@Decolo
Did some research on Failed to fetch error. Possibly it's the issue for the cross-domain. Is there any error message related to this? Can you check if that's related?

@Decolo
Copy link
Author

Decolo commented Sep 25, 2023

@yuhao900914
Hi, Alyssa. Now the error Failed to fetch seems to disappear.
But recently, met a new issue Amplitude Logger [Error]: Unexpected end of JSON input
image
Can u help to figure it out pls? Thank u a lot~

Plus:
Our site url is https://jobright.ai/ .

@Decolo
Copy link
Author

Decolo commented Oct 10, 2023

any update, pls @yuhao900914

@Decolo
Copy link
Author

Decolo commented Oct 13, 2023

image

It seems like an issue happened in client side. Did the sdk support retrying when fail to send request /httpapi. Or I have to try catch the error and retry it manually?

@Junlin-Zhu
Copy link

Do we have any updates on this?

@Junlin-Zhu
Copy link

For the Unexpected end of JSON input issue, on my side, there is a clear reproduce step:

  1. If I connect the vpn to US endpoint, the trace request went through successfully.
  2. If I disconnect the vpn and my ip location is in China, the request failed with this output.

image

@kbsali
Copy link

kbsali commented Jan 2, 2024

same problem for me

@zhen1asemen1uk
Copy link

Hello everyone. I faced the same error and got what happened. My router(or in your case, it can be an ads blocker extension) blocks Amplitude to save my privacy.

If turn off all extensions and connect for example to a mobile wi-fi network everything works ⚙️

Screenshot 2024-03-28 at 12 58 09 Screenshot 2024-03-28 at 12 58 23 Screenshot 2024-03-28 at 13 00 22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants