Automattic / wp-calypso

The JavaScript and API powered WordPress.com
https://developer.wordpress.com
GNU General Public License v2.0
12.42k stars 1.99k forks source link

Loading Tracks twice on WPCOM? #55723

Open gravityrail opened 3 years ago

gravityrail commented 3 years ago

Impacted plugin

Jetpack

Steps to Reproduce

  1. Load any wpcom blog page, e.g. http://goldsounds.blog/
  2. Inspect the DOM or network for "w.js"
  3. You will see two copies of w.js are loaded:
<script crossorigin="anonymous" src="//stats.wp.com/w.js?ver=202134" id="jp-tracks-js"></script>

and

<script src="//stats.wp.com/w.js?61" defer=""></script>

This results in stats like initial-visibility firing twice with different random numbers, among probably other side-effects:

http://pixel.wp.com/g.gif?x_stats-initial-visibility=visible&v=wpcom-no-pv&rand=0.8676031953165511
// separately
http://pixel.wp.com/g.gif?x_stats-initial-visibility=visible&v=wpcom-no-pv&rand=0.22792906811760094

The datestamped w.js request comes from class-tracking.php in Jetpack.

The other w.js has its W_JS_VER suffix of 61 set in stats.php in WPCOM, and I believe is also rendered to the page from that file (directly as HTML, not enqueued like the Jetpack version)

A clear and concise description of what you expected to happen.

We should only load w.js once, and fire stats once.

What actually happened

We load w.js twice and fire stats twice.

Other information

No response

Operating System

macOS

OS Version

11.5.2

Browser

Chrome/Chromium

Browser Version(s)

92

kraftbj commented 3 years ago

I'm going to move this over to the Calypso repo for WP.com to track.

When Jetpack enqueues w.js, we do it "the WordPress" way with the same jp-tracks handle, so WordPress should ensure those don't duplicate. It looks like, scanning wp.com source code, there are various instances of adding a script tag directly (the notifications panel in the admin bar when logged in being one).