Skip to content

feat(analytics): track settings changed event(s)#718

Open
kjmitchelljr wants to merge 13 commits into
mainfrom
analytics/693-settings-changed-event
Open

feat(analytics): track settings changed event(s)#718
kjmitchelljr wants to merge 13 commits into
mainfrom
analytics/693-settings-changed-event

Conversation

@kjmitchelljr
Copy link
Copy Markdown
Collaborator

@kjmitchelljr kjmitchelljr commented May 14, 2026

Summary

Implements detailed event tracking for settings changes across Banner, Offerwall, and Widget tools

Changes

  • State Diffing: Added a recursive utility to compare profile states, tracking modified fields
  • Centralized Store Logic: Refactored createToolStoreUtils to integrate diffing directly into the profile commit
  • Analytic Decision: Updated the save hook to trigger ${tool}_settings_changed events only when changes occur

Related Issues

Closes #693

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 14, 2026

Deployment results

Worker Alias URL Outcome
API - staging success
CDN - staging success
App - aad5ce6c success

Logs #26470815019

@kjmitchelljr kjmitchelljr self-assigned this May 14, 2026
@kjmitchelljr kjmitchelljr requested review from DarianM and sidvishnoi and removed request for DarianM May 20, 2026 00:24
current: object,
): ChangedFields {
const result: Record<string, boolean | string> = {}
walk(prev as PlainObject | undefined, current as PlainObject, '', result)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using this package: https://www.npmjs.com/package/microdiff

changed: ChangedFields,
): void {
if (Object.keys(changed).length === 0) return
trackFn(`${tool}_settings_changed`, { changed })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this changed. prefix in all properties given event name says _changed?

}
}

export function trackSettingsEvent(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is used only in useSaveProfile, consider inlining it there instead of adding to general analytics.

Comment on lines 13 to +15
| [event: `${Tool}_profile_saved`]
| [event: `${Tool}_script_generated`]
| [event: `${Tool}_settings_changed`, data: SettingsChangedData]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include this data in saved/generated events instead of a new event? Given either of these events will be fired immediately after this change event.


snapshots.set(activeTab, current)
store.profilesUpdate.delete(activeTab)
persistSnapshots()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why persist all snapshots when committing only active profile?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sidvishnoi I can verify why this is the case, initially I just took the logic that was in commitProfile() in the separate stores and brought it over. Since the localStorage.setItem() was being called twice once in commitProfile() and once commitAllProfiles() I decided to wrap in a function, but could leave as it is only a one-liner

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to address later on..

Comment thread frontend/app/stores/widget-store.ts
@@ -0,0 +1,47 @@
export type ChangedFields = Partial<Record<`field.${string}`, boolean | string>>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will take up less space (visually as well as in storage):

Suggested change
export type ChangedFields = Partial<Record<`field.${string}`, boolean | string>>
export type ChangedFields = Partial<Record<`f.${string}`, boolean | string>>

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.

Track changed profile fields on save (settings_changed event)

2 participants