site-kit-wp: Missing view in Google Analytics connection process

Bug Description

Google Analytics Views are missing on the connection screen: Connect Service -> Analytics.

Steps to reproduce

  1. Go to ‘Admin > Site Kit > Dashboard’
  2. Click on ‘Set Up Analytics’
  3. See a message “An existing analytics tag was found on your site with the id UA-123456-7. If later on you decide to replace this tag, Site Kit can place the new tag for you. Make sure you remove the old tag first.”
  4. ‘Account’ and ‘Property’ dropdowns show correct values.
  5. The ‘View’ dropdown does not contain correct available views. It only shows one and even that one is from another ‘Property’.

Expected behavior

The ‘View’ dropdown should display Views from the pre-selected ‘Property’.

Additional Context

  • PHP Version: 7.0.27-1~dotdeb+8.1
  • OS: MacOS Mojave 10.14.5
  • Browser: chrome
  • Plugin Version: 1.0.0-beta.1
  • Device: MacBook Pro (13-inch, 2019, Four Thunderbolt 3 ports)

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

Acceptance criteria

  • Views should be retrieved for the property matching the site URL or the existing tag property in the case it has been found, regardless of the position of the property in the properties response from the API.
  • Account and property should be preselected in the drop downs accordingly regardless of the position of the property in the properties response from the API.

Implementation Brief

This issue is not specific to exiting tag found. It is also reproducible when tag is not found.

We are relying on the property being the first index of the properties array in these lines https://github.com/google/site-kit-wp/blob/eeec310f16421555f3c9ce8b46daed2e3858b049/includes/Modules/Analytics.php#L1137-L1138

We do not need to account for property of existing tag in server side as we are removing wp_head tag detection in https://github.com/google/site-kit-wp/issues/83 We need to filter the properties array to find the matching one comparing websiteUrl value against the site url instead of retrieving the account id and property id from index 0

Also make sure to reindex $url_matches as it will return index other than 0 if property is not the first one in the list, therefor won’t be found in https://github.com/google/site-kit-wp/blob/develop/assets/js/modules/analytics/setup.js#L278 https://github.com/google/site-kit-wp/blob/develop/includes/Modules/Analytics.php#1060 should be $matched_property = array_values( $url_matches );

Dependecies Depends on https://github.com/google/site-kit-wp/issues/83 to remove wp_head tag detection. #83 (merged)

Changelog entry

  • Ensure that available Analytics profiles are exposed in dropdown, correctly based on the property.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 22 (15 by maintainers)

Most upvoted comments

Also make sure to reindex $url_matches as it will return index other than 0 if property is not the first one in the list, therefor won’t be found in https://github.com/google/site-kit-wp/blob/develop/assets/js/modules/analytics/setup.js#L278 https://github.com/google/site-kit-wp/blob/develop/includes/Modules/Analytics.php#1060 should be $matched_property = array_values( $url_matches );

This part of the IB no longer appears to be relevant as of this commit (https://github.com/google/site-kit-wp/commit/b733ba1190b879b286a22c0435a72fdaa4a98343) which was part of #83 (#434). matchedProperty now references a single site object, (no longer an array).

@martinkrcho Thanks for checking. I can’t replicate it myself but we get this assigned and looked into.