Skip to content

feat: add data-ol-link-track click tracking to Follow and reading log buttons#12367

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/add-ol-click-track-handling
Open

feat: add data-ol-link-track click tracking to Follow and reading log buttons#12367
Copilot wants to merge 2 commits intomasterfrom
copilot/add-ol-click-track-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Summary

Adds data-ol-link-track attributes 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 optional link_track parameter; a link_track_attr variable 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.htmlFollow|PatronPage
  • templates/account/view.html (My Books / reading-log pages) → Follow|MyBooksPage
  • templates/account/follows.html (Follows management page) → Follow|FollowsPage
  • templates/lists/list_follow.html (lists carousel on book pages) → Follow|BookPage

Commit 2 — Reading log shelf buttons (ReadingLog|<Action>)

  • templates/my_books/primary_action.html — sets a track_value conditional on current read state:
    • No status (logged in) → ReadingLog|WantToRead
    • Status 2 → ReadingLog|CurrentlyReading
    • Status 3 → ReadingLog|AlreadyRead
    • No work / logged out → ReadingLog|AddToList
  • templates/my_books/dropdown_content.html — explicit tracking on each button in the shelf dropdown:
    • ReadingLog|RemoveFromShelf
    • ReadingLog|WantToRead
    • ReadingLog|CurrentlyReading
    • ReadingLog|AlreadyRead

Evidence

Tracking values follow the existing Category|Action pattern used across the codebase (e.g. CTAClick|Edit, Download|epub_ia, MyBooksSidebar|WantToRead).

The link_track parameter on Follow.html is optional (defaults to '') so all existing callers continue to work without modification.

Copilot AI and others added 2 commits April 14, 2026 01:32
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>
Copilot AI requested a review from mekarpeles April 14, 2026 01:34
@mekarpeles mekarpeles marked this pull request as ready for review April 14, 2026 01:42
Copilot AI review requested due to automatic review settings April 14, 2026 01:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.html with an optional link_track parameter and apply it to both logged-in (submit button) and logged-out (login redirect link) states.
  • Add data-ol-link-track tracking to the Reading Log primary action button with a computed track_value based 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 ''
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

3 participants