Skip to content

Stop sending the signed-in viewer's WordPress user ID with analytics - #2334

Merged
subodhr258 merged 1 commit into
developfrom
fix/stop-sending-wp-user-id
Nov 5, 2026
Merged

subodhr258 merged 1 commit into
developfrom
fix/stop-sending-wp-user-id

Conversation

@subodhr258

Copy link
Copy Markdown
Collaborator

Closes rtCamp/godam-plugin-wp#104. Target: GoDAM 2.8.0.

What this changes

The plugin printed the signed-in viewer's WordPress user ID into every front-end page (videoAnalyticsParams.userId) and sent it as wp_user_id with every analytics event. The analytics service stores it, but nothing reads it: no report, rollup or dashboard uses the field. On a page cache it was also wrong, sending one visitor's ID for everyone served that copy.

Now userId is always 0.

Before After
videoAnalyticsParams.userId in the page, signed-in viewer their user ID 0
wp_user_id sent by the player their user ID 0
wp_user_id sent by GoDAM for Woo (Shoppable gallery, Reel Pop) their user ID 0, no Woo change needed
Analytics numbers unchanged (the field is never read)

The key stays in the page, because the player and the Woo senders read it. The media library's own userId (wp-admin only) is unchanged.

Code

admin/godam-transcoder-functions.php, rtgodam_get_localize_array():

-	$current_user = wp_get_current_user();
-
-	$localize_array['userId'] = $current_user->ID;
+	$localize_array['userId'] = 0;

Tests

  • tests/php/ViewerEmailNotInPageTest.php and tests/php/VisitorLocationParamTest.php sign in user 7 and now expect userId to be 0. Both pass locally (6 tests).
  • PHPCS clean on the changed files.
  • Not run on a live site: the change is one value in the localized array, and the senders already turn 0 into wp_user_id: 0 (analytics-helpers.js:239).

Risk

risk: low: one value in front-end page data that nothing downstream reads. Purge any page cache after updating so cached pages stop carrying old IDs.

Follow-ups, already tracked in rtCamp/godam-analytics#364: the service stops storing wp_user_id from older plugins, and a one-off cleanup clears the IDs already stored.

The page now carries userId 0, so the player and the GoDAM for Woo
senders send wp_user_id 0. No analytics report reads the field.

Refs rtCamp/godam-plugin-wp#104
@subodhr258 subodhr258 added the risk: low QA automation only (Dependabot fixes, copy, CSS) label Nov 5, 2026
@subodhr258 subodhr258 self-assigned this Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
12 0 12

⚠️ Warnings (12)

📁 readme.txt (1 warning)
📍 Line 🔖 Check 💬 Message
0 mismatched_plugin_name Plugin name "GoDAM - Video Hosting for LMS & Online Courses" is different from the name declared in plugin header "GoDAM".
📁 assets/build/css/main.css (1 warning)
📍 Line 🔖 Check 💬 Message
0 EnqueuedStylesScope This style is being loaded in all contexts.
📁 assets/src/libs/analytics.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/11/05/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
📁 assets/build/js/main.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/11/05/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@KMchaudhary

Copy link
Copy Markdown
Collaborator

Review — looks good. Verified $current_user was only used to populate userId, so dropping wp_get_current_user() is safe, and the only JS readers of userId are the analytics wp_user_id field (parseInt(userId,10)||0 → 0). The media library's own easydamMediaLibrary.userId is untouched. Both PHP tests updated to expect 0. 👍 — just remember the cache-purge note for cached pages carrying old IDs.

@rudrakshi-gupta

Copy link
Copy Markdown
Member

Code review

Verdict: LGTM, no blocking issues. A one-value change, and the claim it rests on ("nothing reads wp_user_id") holds up.

What I verified

Check Result
Front-end readers of userId / wp_user_id in this repo Only analytics-helpers.js:239 (parseInt( userId, 10 ) || 0). The other userId keys (class-assets.php:346, class-pages.php:799, media-library/utility.js) are separate wp-admin objects and are untouched.
godam-analytics: does anything read it? No. Every match in app/routers/analytics.py is either the < 0 validation (0 passes) or a write via get_default_value("wp_user_id", ...). Nothing in tasks/processing.py (rollups) or any query reads it back.
GoDAM for Woo Only reel-pops/analytics/analytics.js:82 and godam-video-product-gallery/analytics.js:119, both parseInt( userId, 10 ) || 0, so they send 0 with no change, as stated.
Central (godam-core) Its own player already sends wp_user_id: 0 (frontend/.../lib/analytics.ts:97).
No leftover $current_user use in rtgodam_get_localize_array() None, so no undefined-variable notice
ViewerEmailNotInPageTest + VisitorLocationParamTest 6 tests pass (user 7 signed in, userId is 0)
Full PHPUnit suite 1344 tests pass
PHPCS on the changed files Clean

Notes (non-blocking)

  • Keeping the key at 0 instead of removing it is the right call: it avoids touching the player and the Woo senders, and it keeps the page params identical for every visitor, so page caches stay correct.
  • A follow-up could drop wp_user_id from the request body and the Woo senders entirely once the analytics service stops storing it (godam-analytics#364), so the field doesn't keep looking meaningful.

Review drafted with Claude.

@subodhr258
subodhr258 merged commit aa87f82 into develop Nov 5, 2026
6 checks passed
@subodhr258
subodhr258 deleted the fix/stop-sending-wp-user-id branch November 5, 2026 13:53
subodhr258 added a commit that referenced this pull request Nov 6, 2026
* fix(deps): bump follow-redirects to 1.16.2 for Dependabot alert 398 (#2314)

Pins follow-redirects 1.16.2 in overrides (GHSA-mrwp-f3q8-3g9p). Build output is byte-identical; follow-redirects is only used by axios on Node and by webpack-dev-server.

* Update Changelog (#2326)

* Let the analytics service work out the visitor's location (#2214)

* Let the analytics service work out the visitor's location

The page params that GoDAM prints on every front-end page no longer carry
`locationIP`, and the analytics request body no longer has a `location_ip`
field. The analytics service works out the location from the request itself.

Merge after the analytics service reads the address from the request
(rtCamp/godam-analytics#364, item 1).

Tests: the request-body helper and the page params are both checked for the
absence of the address, including a page cached by an older version.

* Keep the JS tests clear of the sibling change's lines

Move the new location tests to the end of the file and leave the shared fixture lines untouched, so this branch and the one that stops sending the viewer's email do not conflict in the test file.

* docs: note that rtgodam_get_user_ip() is kept for other plugins

Nothing in GoDAM calls it after this PR; it stays as a public helper.

Addresses review: #2214 (comment)

* Run the PHP unit tests before publishing to WordPress.org (#2335)

release_on_tag.yml now calls the PHPUnit workflow as a tests job, and
the deploy job needs it, so a tag on a commit with failing tests no
longer reaches WordPress.org.

* Stop sending the signed-in viewer's WordPress user ID with analytics (#2334)

The page now carries userId 0, so the player and the GoDAM for Woo
senders send wp_user_id 0. No analytics report reads the field.

Refs rtCamp/godam-plugin-wp#104

* Point the Vimeo migration links at Central's Vimeo connect tab (#2333)

Both links in the Vimeo migration tab went to Central's home page and
general settings page. They now open Settings > Third-party apps, where
the Vimeo account is connected, and a Step 1 line at the top of the
panel says so.

* Wait for the visitor's statistics consent (WP Consent API) before GoDAM analytics stores or sends anything (#2332)

* feat(analytics): wait for WP Consent API statistics consent before tracking visitors

With the WP Consent API active, GoDAM's video and image-hotspot analytics store
nothing in the visitor's browser and send nothing to analytics.godam.io until
wp_has_consent( 'statistics' ) is true. Tracking starts if the visitor agrees
mid-page, and GoDAM's items are deleted if they withdraw. Sites without the
API keep today's behaviour; the godam_visitor_tracking_enabled filter turns
visitor tracking off entirely.

- utils/consent.js: one consent check, folded into shouldSkipAnalytics(), plus
  a consent-aware storage for the analytics library (visitor id in memory until
  consent) and the grant/withdraw listeners.
- The first-view flag and the layer-click buffer are not written without consent.
- Visitor_Consent: the filter, WP Consent API registration, and the three
  browser items listed with wp_add_cookie_info().

Part of rtCamp/godam-plugin-wp#47 (Phase 1, first PR).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(analytics): keep a returning visitor's id when consent is confirmed after page load

The WP Consent API's script prints after GoDAM's, so on every page GoDAM first
sees "no consent yet" and the analytics library makes a fresh id in memory.
When consent was then confirmed, that id overwrote the visitor's stored one, so
a returning visitor counted as new on every page. Found testing with CookieYes.

On grant, an id already on the device now wins, the live instance switches to
it (setAnonymousId), and the grant callbacks wait until it has. Test added; it
fails without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(analytics): honour a recorded statistics refusal when the banner sets no consent type

wp_has_consent() returns true whenever no consent type is set on the page.
CookieYes 3.5 sets the type only when the visitor acts, so on the page after
"Reject All" it was unset and GoDAM tracked again despite the
wp_consent_statistics=deny cookie. An explicit deny cookie now always wins.
Test added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(analytics): hold events until the visitor chooses; setAnalyticsConsent() for custom banners

Meets rtCamp/godam-plugin-wp#55:
- Events from before the visitor's choice wait in memory (nothing stored, nothing
  sent): views of videos seen before consent, plays, and layer clicks are sent if
  the visitor accepts on that page and discarded if they refuse. Held events go
  out with the visitor's final id.
- window.GoDAM.setAnalyticsConsent( true | false ) lets a banner without WP
  Consent API support pass the choice; the godam_visitor_tracking_requires_consent
  filter makes GoDAM wait for it. One call reaches both the player and the
  image-page bundles.
- A readme FAQ entry documents the filters and the JavaScript call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(analytics): expose the consent check on window.GoDAM for add-ons

GoDAM for Woo can now gate its own senders with GoDAM's consent state:
window.GoDAM.hasStatisticsConsent(), holdUntilConsent(fn) (held add-on events
are discarded with GoDAM's own on refusal), onStatisticsConsent(fn), and
onStatisticsConsentWithdrawn(fn), called once per refusal or withdrawal after
GoDAM has deleted its own items, so the add-on can delete its cookies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: start a new visitor id when consent is withdrawn and given again on the same page

Withdrawal cleared the browser but kept the id in memory, so accepting again
wrote the deleted id back. Memory is now emptied and the live instance gets a
fresh id, kept in memory while consent is off.

Addresses review: #2332 (comment)

* fix: send held events with the stored visitor id, not the library's live id

When the library had not switched to a returning visitor's stored id within
the 1 s wait, held events went out under the in-memory id. They now read the
id from GoDAM's own storage, which has the stored id once consent is confirmed.

Addresses review: #2332 (comment)

* fix: start nothing if consent is refused while the grant waits for the stored id

The grant step can wait up to a second for the library to switch to a returning
visitor's id. A refusal in that window was followed by the grant step re-arming
view tracking. It now checks consent is still given before it runs.

Addresses review: #2332 (comment)

* fix: tell add-ons about a refusal once, not on every repeated deny

Banners can fire the same deny more than once; each one called the add-on
withdrawal callbacks again. They now run once per refusal, and again only
after the visitor accepts and refuses again.

Addresses review: #2332 (comment)

* fix: drop the unused category from the consent settings sent to the page

The JS fixes the category to statistics and never read the setting.

Addresses review: #2332 (comment)

* fix: re-check consent on load and first interaction for delayed consent scripts

A delay-JavaScript optimizer can hold the WP Consent API script back, and it
fires no event when it loads, so events waiting for consent could stay held.
GoDAM now re-checks once on load and once on the first pointerdown, keydown or
scroll.

Addresses review: #2332 (comment)

* docs: correct the comment on re-checking videos after consent

Held views are sent by their held action; the re-observe covers videos left
observed while analytics was not ready, and refuse-then-accept on one page.

Addresses review: #2332 (comment)

* docs: scope the consent FAQ to GoDAM's own analytics

GoDAM for Woo's Shoppable Video and Reel Pop counts are gated in a GoDAM for
Woo update, so the FAQ says what this plugin covers.

Addresses review: #2332 (comment)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Multi-language captions + multilingual transcription (plugin side) (#2174)

* Add multi-language captions + multilingual transcription support

Integrate the plugin with GoDAM Central's first-class caption tracks and
multilingual/multi-audio transcription (godam-core #1340).

Backend proxies (class-transcription.php):
- generate_transcription forwards optional `language` (BCP 47, or auto/multi
  detection) and `track_index` to process_transcription.
- New caption-track proxies to the SaaS api/captions.py: list, upload, update,
  delete and set-default, resolving the job-ID per attachment and injecting the
  licence key server-side. SaaS validation reasons are surfaced verbatim.

Editor UI (video-editor Transcription tab):
- Transcription language selector wired into Generate.
- Caption manager dialog: per-track rows (label, language, Generated/Uploaded
  badge, cue count, default marker) with set-default, edit, replace, download
  and delete; add form with client-side file read; cue editor for round-trippable
  tracks (disabled for has_rich_formatting).

Player:
- transcriptManager builds one subtitle <track> per caption_tracks row (default
  first), with a legacy single-transcript fallback; dedup by source URL so two
  same-language tracks both render.

* Fix the caption manager list and keep WordPress and Central captions in sync

- Caption manager reads Central's `captions` list (it read `caption_tracks`,
  so the list was always empty), shows list errors, and offers the cue editor
  only for tracks without rich formatting.
- Generate starts on "Account default" and sends no language, so Central's
  account language applies; the list matches the languages Central accepts.
- Player: a transcript uploaded in WordPress plays first, then every ready
  Central caption track; the cached copy is only a fallback when Central is
  unreachable. Tracks still generating no longer hide the rest.
- The transcription callback caches the default caption from `caption_tracks`
  instead of whichever audio track finished last, and never overwrites a
  WordPress upload. Caption-manager changes re-cache it and clear the
  deleted flag.
- Language codes keep their case and subtags (pt-BR, zh-Hant-TW); caption
  text is no longer unslashed twice; cue timestamps reuse the player's writer.

* Keep the WordPress transcript track on source changes and tidy the caption manager

Found in a live test against GoDAM Central:
- addRemoteTextTrack(..., false) lets video.js drop the track when the player
  changes its source. The transcript uploaded in WordPress is added before
  the Central request returns, so it vanished in 1 of 4 page loads. Pass true.
- Caption manager had no styles: label and language ran together. Add row
  layout for the manager and cue editor (both render outside the editor root).
- A generated track with no file shows its status and can't be set as
  default; "1 cue" is singular; Edit and Replace use edit and upload icons.

* Match GoDAM Central's caption dialog and keep caption order and edits stable

- Caption manager: the picked file's name shows beside "Choose another file";
  each row has a Default badge and a Generated/Uploaded badge; the default and
  replace icons match Central's dialog.
- Rows and the player's CC menu are sorted A to Z by label, so setting a
  default no longer moves a track; the player switches the default on directly.
- The label is required and must be unique on the video; a taken name is
  flagged in the field before upload.
- The player adds each track's revision to its file URL, so an edit made in
  Central reaches visitors at once instead of after the CDN's 30-day browser
  cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Explain caption tracks and offer the upgrade to free and unconnected sites

The caption manager showed a raw "not transcoded" error to sites with no
GoDAM account, and Central's "No active subscription" to free accounts.
Both now see what paid plans add, a See plans link, and Connect your
account when no key is set. Upload File keeps working for them.

- caption_context checks the API key before the video's job, so a site
  with no account is told to connect one.
- call_saas maps Central's NoActiveSubscription and SubscriptionInactive
  to rtgodam_no_subscription.
- The Add caption track button is hidden when the list cannot load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Disable Generate for videos GoDAM has not transcoded

Transcription runs on GoDAM, so a video it has not transcoded (no job)
cannot be transcribed; clicking Generate only returned an error. The
transcription GET route now says whether the video has a job, and the
Transcription tab disables Generate and the language picker for one
without, with a line saying why and that a caption file can still be
uploaded. The caption manager's plan notice is renamed to
"Multi-language captions are part of the paid GoDAM plans".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Captions: keep Central's tracks after a WordPress delete, follow Central's default, warn before deleting a track

- Delete in the Transcription tab now drops only WordPress's copy: the player
  still plays the caption tracks stored in GoDAM Central.
- The Transcription tab re-reads Central's default caption when it opens, and
  the video SEO data queues a background re-check at most every 12 hours, so
  changes made in Central's own dashboard reach WordPress without a callback.
- Deleting a caption track asks first, saying every site using the video loses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Captions: refresh Central defaults in batches, not one cron event per video

Right after an update every existing video has never been checked, so a
sitemap page queued one cron event (and one Central call) per video at once.
Due videos now go into one non-autoloaded queue: a page view adds at most 20,
the queue holds at most 500, and a single cron event refreshes 20 per run,
every 5 minutes, until the queue is empty. Review: #2174.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Captions: check the typed language code and the file size in the dialog

- "Other (enter code)": a value Central would refuse, such as "English", now
  shows "Enter a language code, such as cy or pt-BR, not the language name."
  under the field and keeps Add disabled.
- Add and Replace refuse a file over Central's 1 MB limit before reading it.
Review: #2174.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: KMchaudhary <kuldipkumar.chaudhary@rtcamp.com>
Co-authored-by: Subodh Rajpopat <subodh.rajpopat@rtcamp.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Set WPBakery param defaults in settings['default'] as well as std (#2323)

WPBakery 9.1 deprecated the 'std' key and logs a notice for every
element that still uses it without settings['default'] (7 lines per
page load from these 5 elements). Add settings['default'] with the same
value next to each of the 39 'std' keys. Keep 'std' so WPBakery 8.x,
which reads only 'std', keeps the same defaults.

* Ask sites on GoDAM for WooCommerce older than 2.3.1 to update it (#2338)

Earlier versions send their Shoppable Video and Reel Pops analytics
without waiting for the visitor's consent (GoDAM 2.8.0 holds its own).

* Restrict the MetForm and poll REST routes to Media Editor users (#2339)

* Restrict the MetForm and poll REST routes to Media Editor users

/metforms, /metform, /polls and /poll/{id} used __return_true, so anyone
could call them. /metform renders any form ID through the [metform]
shortcode, which shows pending, private and scheduled builder forms to
logged-out visitors, and /polls returns every WP-Polls row, including
scheduled polls.

Only the Media Editor calls these routes; the player renders MetForm and
poll layers on the server. They now use forms_permissions_check
(upload_files), like the other form routes.

* Send the REST nonce from the Media Editor's poll client

The poll routes now need upload_files. polls.js sent no X-WP-Nonce, so
WordPress treated the editor's cookie request as logged out and the Poll
layer's picker came back empty. Same header as gravity-forms.js (#2049),
with a Jest test that both poll requests carry it.

* Bump version to 2.8.0 and add the v2.8.0 changelog (#2337)

* Bump version to 2.8.0 and add the v2.8.0 changelog

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Set @SInCE n.e.x.t to 2.8.0 and regenerate the POT after #2174 and #2332

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Add the WPBakery 9.1 fix to the 2.8.0 changelog and regenerate the POT

Merges develop (#2323), adds its Fix line to CHANGELOG.md and readme.txt,
and regenerates languages/godam.pot with --slug=godam so the bug-report
URL is /plugin/godam and the WPBakery line references are current.

* Add the GoDAM for Woo 2.3.1 notice to the 2.8.0 changelog and refresh the POT

Merges develop (#2338, #2339). Regenerated with --slug=godam; only
source references moved.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Rudrakshi Gupta <109859631+rudrakshi-gupta@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Kuldip Chaudhary <64731232+KMchaudhary@users.noreply.github.com>
Co-authored-by: KMchaudhary <kuldipkumar.chaudhary@rtcamp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: low QA automation only (Dependabot fixes, copy, CSS)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants