site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Tracking: "standalone" sendAnalyticsTrackingEvent missing configuration

Open aaemnnosttv opened this issue 7 years ago • 4 comments

Bug Description

\Google\Site_Kit\Core\Util\Tracking::print_standalone_event_tracking_script defines a global sendAnalyticsTrackingEvent function in JavaScript for sending gtag events.

According to the method's docblock:

"This is used for when not on a screen owned by Site Kit."

The problem is that the main part of this function is dynamically defined in PHP like so:

<?php if ( ! empty( $track_id ) ) { ?>
    if ( window.googlesitekitTrackingEnabled ) {
        gtag( 'event', eventName, {
            send_to: '<?php echo esc_attr( self::TRACKING_ID ); ?>', 
            event_category: eventCategory,
        } );
    }
<?php } ?>

The local variable $track_id is never provided in the given scope so this conditional will always be falsy in all cases, resulting in the actual call to gtag() not appearing in the function.

https://github.com/google/site-kit-wp/blob/9a262cd18c33995ce5ec81bc300ff055dff2a153/includes/Core/Util/Tracking.php#L177-L196


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • When on the WP dashboard or plugins screen (the latter only when the user isn't authenticated yet), the source code should contain the sendAnalyticsTrackingEvent() function, and it should include a call to the gtag() function (wrapped in a check if tracking is enabled).

Implementation Brief

  • Remove the wrapping if ( ! empty( $track_id ) ) conditional referencing the undefined $track_id variable.

Changelog entry

  • Fix tracking script being broken in WP dashboard and plugins screen due to an undefined variable PHP notice.

aaemnnosttv avatar Jul 04 '19 12:07 aaemnnosttv

@felixarntz Brief ready for review

aaemnnosttv avatar Jul 12 '19 14:07 aaemnnosttv

Implementation brief looking good.

felixarntz avatar Jul 15 '19 08:07 felixarntz

@lucymtc - Could you review this one and add an estimate label ASAP? We'd like to determine whether or not this is something that could make it into this week's release (potentially replacing other tickets to do so, if needed). Thanks so much!

lilybonney avatar Jul 15 '19 22:07 lilybonney

QA looking good!

felixarntz avatar Jul 16 '19 15:07 felixarntz