Skip to content

Doesn't work with Next.js in APIs (events seem sent but aren't available on Amplitude dashboard) #123

@Vadorequest

Description

@Vadorequest

Expected Behavior

Event sent using @amplitude/node should be available on the Amplitude Dashboard

Current Behavior

Events aren't available in Amplitude, as if they were never received.

Logs:

info  - ready on http://localhost:8888
2021-06-22T18:09:53.157Z [modules/core/amplitude/amplitudeServerClient] Logging Amplitude event "api-invoked" with properties: { apiEndpoint: 'status' }
2021-06-22T18:09:53.157Z [modules/core/amplitude/amplitudeServerClient] NodeClient {
  _events: [],
  _responseListeners: [],
  _flushTimer: null,
  _apiKey: '5ea02d86a6840c165fcc01377131fa13',
  _options: {
    serverUrl: 'https://api2.amplitude.com/2/httpapi',
    debug: true,
    maxCachedEvents: 16000,
    logLevel: 3,
    optOut: false,
    retryTimeouts: [
       100,  100,  200,  200,
       400,  400,  800,  800,
      1600, 1600, 3200, 3200
    ],
    retryClass: null,
    transportClass: null,
    uploadIntervalInSec: 0,
    minIdLength: null
  },
  _transportWithRetry: RetryHandler {
    _apiKey: '5ea02d86a6840c165fcc01377131fa13',
    _options: {
      serverUrl: 'https://api2.amplitude.com/2/httpapi',
      debug: true,
      maxCachedEvents: 16000,
      logLevel: 3,
      optOut: false,
      retryTimeouts: [Array],
      retryClass: null,
      transportClass: null,
      uploadIntervalInSec: 0,
      minIdLength: null
    },
    _transport: HTTPTransport {
      options: [Object],
      _uploadInProgress: false,
      _requestQueue: [AsyncQueue],
      module: [Object]
    },
    _idToBuffer: Map(0) {},
    _eventsInRetry: 0
  }
} 5ea02d86a6840c165fcc01377131fa13

response {
  status: 'success',
  statusCode: 200,
  body: {
    eventsIngested: 0,
    payloadSizeBytes: 58,
    serverUploadTime: 1624385394010
  }
}

The API key is defined, the response is sent and awaited for, the result is a success, but there are no data in the Amplitude Dashboard. The @amplitude/react-amplitude package works fine on the browser, though.

It doesn't work locally, and it doesn't work on Vercel either.

image

image

I'm not sure what's wrong.

Possible Solution

Potentially related to flushing and https://vercel.com/docs/platform/limits#streaming-responses, but I've flushed and awaited for the flush to avoid any issue. Also, it doesn't even work locally.

Steps to Reproduce

  1. git clone git@github.com:UnlyEd/next-right-now.git nrn-refactor-amplitude && cd nrn-refactor-amplitude && git checkout refactor-amplitude && cp .env.local.example .env.local && yarn && yarn start
  2. Go to localhost:8888/api/status and look at the server console

Environment

  • SDK Version: "@amplitude/node": "1.6.1",
  • Node version: v14

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions