diff --git a/admin/godam-transcoder-functions.php b/admin/godam-transcoder-functions.php index 6c5042d9d..c0274e080 100644 --- a/admin/godam-transcoder-functions.php +++ b/admin/godam-transcoder-functions.php @@ -626,11 +626,15 @@ function rtgodam_get_localize_array() { $localize_array = array(); - $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(); - $localize_array['postTitle'] = get_the_title(); + $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(); + // Resolve the title from the queried object, not the global $post: this runs + // on wp_enqueue_scripts, where the loop global can hold an unrelated post + // (first post on archives, or one left behind by a secondary query). Empty + // on non-singular pages — there is no single post to attribute the view to. + $localize_array['postTitle'] = is_singular() ? get_the_title( get_queried_object_id() ) : ''; $localize_array['locationIP'] = rtgodam_get_user_ip(); /** diff --git a/assets/src/js/godam-player/analytics-helpers.js b/assets/src/js/godam-player/analytics-helpers.js index 9e3401fcd..8143afa9a 100644 --- a/assets/src/js/godam-player/analytics-helpers.js +++ b/assets/src/js/godam-player/analytics-helpers.js @@ -206,7 +206,11 @@ export function buildAnalyticsRequestBody( { email: emailId || '', visitor_timestamp: visitorTimestamp || Date.now(), visit_entry_action_url: window.location.href, - visit_entry_action_name: document.title, + // Prefer the WP-resolved post title: document.title is the SEO/document + // title ("Post – Site Name", or whatever an SEO plugin emits), not the + // post title. PHP localizes postTitle only on singular pages; elsewhere + // document.title is the best page name available. + visit_entry_action_name: postTitle || document.title, referer_type: '', referer_name: document.referrer || '', referer_url: document.referrer || '',