-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix: React detection and Analytics batch upload #11478
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { ConsoleLogger as Logger } from '@aws-amplify/core'; | ||
import { AnalyticsAction, ConsoleLogger as Logger } from '@aws-amplify/core'; | ||
import { | ||
putEvents, | ||
PutEventsInput, | ||
PutEventsOutput, | ||
} from '@aws-amplify/core/internals/aws-clients/pinpoint'; | ||
import { EventBuffer, EventObject, EventMap } from '../types'; | ||
import { isAppInForeground } from '../utils/AppUtils'; | ||
import { getAnalyticsUserAgentString } from '../utils/UserAgent'; | ||
|
||
const logger = new Logger('EventsBuffer'); | ||
const RETRYABLE_CODES = [429, 500]; | ||
|
@@ -101,7 +102,11 @@ export default class EventsBuffer { | |
try { | ||
const { credentials, region } = this._config; | ||
const data: PutEventsOutput = await putEvents( | ||
{ credentials, region }, | ||
{ | ||
credentials, | ||
region, | ||
userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this meant to track how often |
||
}, | ||
batchEventParams | ||
); | ||
this._processPutEventsSuccessResponse(data, eventMap); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,15 @@ import { documentExists, processExists, windowExists } from './helpers'; | |
// Tested with react 18.2 - built using Vite | ||
|
||
export function reactWebDetect() { | ||
return documentExists() && !!document.getElementById('react-root'); | ||
const elementKeyPrefixedWithReact = k => { | ||
return k.startsWith('_react') || k.startsWith('__react'); | ||
}; | ||
const elementIsReactEnabled = e => { | ||
return Object.keys(e).find(elementKeyPrefixedWithReact); | ||
}; | ||
const allElementsWithId = () => Array.from(document.querySelectorAll('[id]')); | ||
Comment on lines
+9
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit since this doesn't run often to my understanding but typically we'd want to extract these so they're not recreated every time Second nit would be to use more meaningful parameter names... it's easy enough to intuit that |
||
|
||
return documentExists() && allElementsWithId().some(elementIsReactEnabled); | ||
} | ||
|
||
export function reactSSRDetect() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had made a change to this file I rolled back, but prettier is really insistent that this line be changed... 🙄