I'm trying to record events using the JS Amplitude API.
The setup instructions are to put code in the <head>
of pages.
See Full instructions here.
Since I'm using React, I put the code in index.html
The event I'm trying to record is executed on componentDidMount
on various pages:
componentDidMount() {
amplitude.getInstance().logEvent("test_profile_accessed", {page: `${test_info}`});
}
However, sometimes the event doesn't record because I get this error:
[Amplitude] Invalid apiKey. Please set a valid apiKey with init() before calling logEvent()
This error only happens every once in a while, with the other times successfully recording.
What is going on? I don't see any documentation about this error anywhere else.