fix: record the real post title in analytics instead of document.title#1941
Open
subodhr258 wants to merge 1 commit into
Open
fix: record the real post title in analytics instead of document.title#1941subodhr258 wants to merge 1 commit into
subodhr258 wants to merge 1 commit into
Conversation
visit_entry_action_name was sent as raw document.title, which on WordPress
is the SEO/document title ("Post Title – Site Name", or whatever an SEO
plugin emits) — so blog-post views were ingested with a polluted title.
Prefer the PHP-resolved post title and keep document.title only as the
fallback for non-singular pages.
postTitle itself was localized via get_the_title() with no ID on
wp_enqueue_scripts, which reads the loop global: on archives/home it
recorded the first post of the loop as the "post title" for every view
on the page, and on singular pages it broke if an earlier secondary
query moved the global. Resolve it from the queried object on singular
pages and send it empty elsewhere.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes analytics payload titles for WordPress pages by using the actual queried post title (instead of the SEO-influenced document.title) when building analytics requests. It improves the correctness of visit_entry_action_name and stabilizes the localized postTitle against loop/global $post pollution.
Changes:
- Update the analytics request body builder to prefer
postTitleoverdocument.titleforvisit_entry_action_name, with a safe fallback. - Update the PHP localization array to derive
postTitlefrom the queried object ID (and set it empty on non-singular pages).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| assets/src/js/godam-player/analytics-helpers.js | Uses localized postTitle for visit_entry_action_name with document.title fallback. |
| admin/godam-transcoder-functions.php | Localizes postTitle using get_queried_object_id() on singular views to avoid loop-global pollution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+629
to
+632
| $localize_array['endpoint'] = RTGODAM_ANALYTICS_BASE; | ||
| $localize_array['isPost'] = empty( is_single() ) ? 0 : is_single(); | ||
| $localize_array['isPage'] = empty( is_page() ) ? 0 : is_page(); | ||
| $localize_array['isArchive'] = empty( is_archive() ) ? 0 : is_archive(); |
elifvish
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Addresses the P1 item "On blog post data ingestion - analytics payload sends wrong post title" from the analytics EPIC rtCamp/godam-analytics#171.
Two related defects in the analytics payload:
visit_entry_action_namewas sent as rawdocument.title. On WordPress that is the SEO/document title —"{Post Title} – {Site Name}"by default, or whatever an SEO plugin (Yoast/RankMath title templates) generates — not the post title. Every blog-post view was ingested with this polluted title. Verified on a live site: post "Hello world!" ingests as "Hello world! – subodh-multisite.rt.gw".postTitlewas localized viaget_the_title()with no post ID onwp_enqueue_scripts, which reads the loop global$post. On archives/home it records the first post of the loop as the post title for every view on that page (confirmed live: blog index sendspostTitle: "Hello world!", postId: 1whileisPost: 0), and on singular pages it silently breaks when a theme/plugin runs a secondary query beforewp_headwithout resetting postdata.Fix
rtgodam_get_localize_array()): resolve the title from the queried object —is_singular() ? get_the_title( get_queried_object_id() ) : ''— immune to loop-global pollution; empty on non-singular pages where there is no single post to attribute the view to.analytics-helpers.js):visit_entry_action_name: postTitle || document.title— the clean WP post title on singular pages,document.titleas fallback elsewhere (on archives the document title is the best available page name).No schema or analytics-service change needed; both fields already exist in the ingest payload. GoDAM Central's client keeps sending
document.titlefor its own (non-WP) pages, which remains correct there.Verification
buildAnalyticsRequestBody()(module executed with stubbed globals): singular →visit_entry_action_name === postTitle; archive → falls back todocument.titlewithpost_title: ''; missingpostTitlekey (stale cached localize) → falls back; unverified-token bail-out unchanged.postTitle: "Hello world!", static page"Sample Page", blog index""— while the post's<title>isHello world! – My WordPress Website, demonstrating the pollution the fix removes.phpcsandwp-scripts lint-jsclean on the changed files; builtgodam-player-analytics.min.jsconfirmed to contain the new expression (build artifacts not committed, per release process).Follow-up (separate repo)
godam-for-wooreel-pops analytics (assets/src/js/reel-pops/analytics/analytics.js) duplicates thevisit_entry_action_name: document.titlepattern and will need the same one-line change; itspost_titlebenefits from this PR automatically since it reads the same localizedvideoAnalyticsParams.