-
Notifications
You must be signed in to change notification settings - Fork 49
feat(autocapture): fetch page actions from remote config #1168
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
base: main
Are you sure you want to change the base?
Conversation
29e1638
to
54dd1b8
Compare
28a3881
to
863c47d
Compare
📝 Documentation updates detected! New suggestion: Document remote configuration support for pageActions in autocapture |
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.
Bug: Remote Config Overwrites Local Data, Triggers Not Updated
The remote configuration for pageActions
has two issues. First, the recomputePageActionsData
function performs a shallow merge, causing undefined
values from remote config (e.g., for labeledEvents
or triggers
) to overwrite existing local pageActions
properties, resulting in data loss. Second, while recomputePageActionsData
reassigns the evaluateTriggers
function, existing event tracking subscriptions (e.g., trackClicks
) retain a reference to the original function. This prevents remote config updates from being applied to active event processing.
packages/plugin-autocapture-browser/src/autocapture-plugin.ts#L185-L199
Amplitude-TypeScript/packages/plugin-autocapture-browser/src/autocapture-plugin.ts
Lines 185 to 199 in 249dd07
// Function to recalculate internal variables when remote config is updated | |
const recomputePageActionsData = (remotePageActions: ElementInteractionsOptions['pageActions']) => { | |
if (remotePageActions) { | |
// Merge remote config with local options | |
options.pageActions = { | |
...options.pageActions, | |
...remotePageActions, | |
}; | |
// Recalculate internal variables | |
groupedLabeledEvents = groupLabeledEventIdsByEventType(Object.values(options.pageActions.labeledEvents ?? {})); | |
labeledEventToTriggerMap = createLabeledEventToTriggerMap(options.pageActions.triggers ?? []); | |
// Update evaluateTriggers function | |
evaluateTriggers = generateEvaluateTriggers(groupedLabeledEvents, labeledEventToTriggerMap, options); |
Comment bugbot run
to trigger another review on this PR
Was this report helpful? Give feedback by reacting with 👍 or 👎
// Log error but don't fail the setup | ||
/* istanbul ignore next */ | ||
config?.loggerProvider?.error(`Failed to fetch remote config: ${String(error)}`); | ||
} |
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.
Nitpick: this try -> catch block isn't necessary. If the error gets thrown from inside of 'then' it will be caught by 'catch'.
}) | ||
.then(async (remoteConfigFetch) => { | ||
try { | ||
const remotePageActions = await remoteConfigFetch.getRemoteConfig('analyticsSDK', 'pageActions'); |
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.
Does the remote config endpoint allow us to return analyticsSDK: { browserSDK, pageActions}
instead of calling these 2 separately?
executeActions(trigger.actions, event); | ||
} | ||
|
||
return event; |
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.
Could this function be moved into a helper function? It looks like it does the same thing as evaluateTriggers
from autocapture-plugin.ts
.then(async (remoteConfigFetch) => { | ||
try { | ||
const remotePageActions = await remoteConfigFetch.getRemoteConfig('analyticsSDK', 'pageActions'); | ||
recomputePageActionsData(remotePageActions as ElementInteractionsOptions['pageActions']); |
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.
Just to confirm, this means that:
- if the fetch fails, it will fallback to the hardcoded configuration?
- up until the fetch is complete, it's going to use the hardcoded config?
Summary
analyticsSDK.pageActions
is fetched now after plugin initialization, this requiresfetchRemoteConfig
to be enabled.Checklist