Skip to content

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Dogfalo
Copy link
Collaborator

@Dogfalo Dogfalo commented Jun 25, 2025

Summary

  • Remote config for key analyticsSDK.pageActions is fetched now after plugin initialization, this requires fetchRemoteConfig to be enabled.
  • It is designed to be non-blocking and doesn't slow down initialization of the plugin.
  • Fixed an error where the wrong operator name was used for checking Element Text in the Labeled Event definition evaluation

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

@Dogfalo Dogfalo changed the title feat: fetch page actions from remote config feat(autocapture): fetch page actions from remote config Jun 25, 2025
@Dogfalo Dogfalo force-pushed the page-actions-remote-config branch from 29e1638 to 54dd1b8 Compare July 7, 2025 23:41
@Dogfalo Dogfalo force-pushed the page-actions-remote-config branch from 28a3881 to 863c47d Compare July 8, 2025 18:50
@Dogfalo Dogfalo marked this pull request as ready for review July 8, 2025 20:31
Copy link

promptless bot commented Jul 8, 2025

📝 Documentation updates detected!

New suggestion: Document remote configuration support for pageActions in autocapture

@Dogfalo Dogfalo requested review from Mercy811 and a team July 8, 2025 20:35
Copy link

@cursor cursor bot left a 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

// 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);

Fix in CursorFix in Web


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)}`);
}
Copy link
Collaborator

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');
Copy link
Collaborator

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;
Copy link
Collaborator

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']);
Copy link
Collaborator

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:

  1. if the fetch fails, it will fallback to the hardcoded configuration?
  2. up until the fetch is complete, it's going to use the hardcoded config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants