feat: add data-ol-link-track click tracking to Follow and reading log buttons#12367
feat: add data-ol-link-track click tracking to Follow and reading log buttons#12367
Conversation
Add link_track parameter to the Follow macro and pass context-specific
tracking values from each call site:
- /people/{username} pages → Follow|PatronPage
- /people/{username}/books* pages → Follow|MyBooksPage
- /account/follows management page → Follow|FollowsPage
- Book page lists carousel → Follow|BookPage
Agent-Logs-Url: https://github.com/internetarchive/openlibrary/sessions/15419c4f-2194-464b-8fb2-1c047ef1896c
Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
Add data-ol-link-track tracking to the Want to Read, Currently Reading, Already Read, and Remove From Shelf buttons in the My Books dropper: - primary_action.html: conditional track_value based on current read state - dropdown_content.html: explicit tracking on each shelf button Also refactor Follow.html to compute link_track_attr once instead of repeating the conditional expression inline twice. Agent-Logs-Url: https://github.com/internetarchive/openlibrary/sessions/15419c4f-2194-464b-8fb2-1c047ef1896c Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds consistent data-ol-link-track analytics attributes to Follow CTAs and Reading Log shelf buttons across key templates, aligning with the existing Category|Action tracking pattern used elsewhere in Open Library templates/macros.
Changes:
- Extend
macros/Follow.htmlwith an optionallink_trackparameter and apply it to both logged-in (submit button) and logged-out (login redirect link) states. - Add
data-ol-link-tracktracking to the Reading Log primary action button with a computedtrack_valuebased on current shelf/read state. - Add explicit tracking attributes to each Reading Log dropdown shelf action (including Remove From Shelf).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| openlibrary/macros/Follow.html | Adds optional link_track param and emits data-ol-link-track on Follow button/link. |
| openlibrary/templates/type/user/view.html | Supplies `Follow |
| openlibrary/templates/account/view.html | Supplies `Follow |
| openlibrary/templates/account/follows.html | Supplies `Follow |
| openlibrary/templates/lists/list_follow.html | Supplies `Follow |
| openlibrary/templates/my_books/primary_action.html | Adds computed tracking value to the primary reading log action button. |
| openlibrary/templates/my_books/dropdown_content.html | Adds per-action tracking to reading log dropdown shelf buttons. |
|
|
||
| $ subscriber = ctx.user and ctx.user.key | ||
| $ custom_request_path = request_path if request_path != '' else request.fullpath | ||
| $ link_track_attr = 'data-ol-link-track="%s"' % link_track if link_track else '' |
There was a problem hiding this comment.
link_track_attr interpolates link_track directly into an HTML attribute without escaping. If link_track ever contains ", <, etc (e.g. from a future caller passing non-constant data), this can break markup and become an attribute-injection/XSS vector. Consider escaping the value (e.g. via websafe()/web.net.htmlquote()) or avoiding string-built attributes by conditionally rendering data-ol-link-track="..." with an escaped $(...) value.
Summary
Adds
data-ol-link-trackattributes to the Follow button and the three reading-log shelf buttons (Want to Read, Currently Reading, Already Read) throughout the site, consistent with how other interactive elements (downloads, search sorts, CTAs) are already tracked.Changes
Commit 1 — Follow buttons (
Follow|<Context>)macros/Follow.html— added optionallink_trackparameter; alink_track_attrvariable is computed once and applied to both the submit<button>(logged-in users) and the login-redirect<a>(logged-out users)templates/type/user/view.html→Follow|PatronPagetemplates/account/view.html(My Books / reading-log pages) →Follow|MyBooksPagetemplates/account/follows.html(Follows management page) →Follow|FollowsPagetemplates/lists/list_follow.html(lists carousel on book pages) →Follow|BookPageCommit 2 — Reading log shelf buttons (
ReadingLog|<Action>)templates/my_books/primary_action.html— sets atrack_valueconditional on current read state:ReadingLog|WantToReadReadingLog|CurrentlyReadingReadingLog|AlreadyReadReadingLog|AddToListtemplates/my_books/dropdown_content.html— explicit tracking on each button in the shelf dropdown:ReadingLog|RemoveFromShelfReadingLog|WantToReadReadingLog|CurrentlyReadingReadingLog|AlreadyReadEvidence
Tracking values follow the existing
Category|Actionpattern used across the codebase (e.g.CTAClick|Edit,Download|epub_ia,MyBooksSidebar|WantToRead).The
link_trackparameter onFollow.htmlis optional (defaults to'') so all existing callers continue to work without modification.