-
Notifications
You must be signed in to change notification settings - Fork 315
Description
Bug Description
At present when a user already has an existing Analytics snippet placed on their site there are duplicate snippets output if a user then chooses to connect the Analytics module within Site Kit. The toggle to "Let Site Kit place code on your site" is toggled on by default - although a user would not be unaware as these configuration options are not available until a user revisits their Site Kit Analytics settings page.
Gif below showing duplicate snippets placed (one manual and another via SK)
Tested as far back as Site Kit 1.21.0, the same occurred - happy to check further back if required.
1.27.0 - video showcasing experience
1.23.0 - video showcasing experience
1.21.0 - video showcasing experience
Steps to reproduce
- Manually insert an Analytics tracking snippet
- Install and setup Site Kit
- Connect the Analytics module
- During the module setup screen a user will not be prompted on whether they want Site Kit tp insert the snippet, rather the module will complete connection
- Analytics snippet appears twice (one manual placement, another via SK)
- A user must go back into their Analytics settings screen within Site Kit to disallow Site Kit to place their snippet
Additional Context
- Started occurring from unknown Site Kit version - checked as far back at 1.21.0 when this same experience was occuring
- No support topics open in relation to this although possible bounce rate implications, testing ongoing
- Occurs with AMP or non AMP sites (tested on transitional mode AMP sites along with non AMP sites)
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When there is an existing Analytics snippet in the frontend, the Analytics snippet from Site Kit should not be placed.
- This should primarily be fixed in the Analytics setup flow; but as well in the Analytics settings panel (e.g. if an existing snippet was inserted after setting up Analytics).
- At some point this used to work as expected, but something must have broken it - apparently a while ago. Note that, while in case of a GTM snippet we now rely on
canUseSnippet
through a filter, we either need to store a separate option to indicate an existing snippet is present or alternatively simply setuseSnippet
tofalse
if that is detected.
Implementation Brief
- Update Analytics’
useExistingTagEffect
to callsetUseSnippet( false )
when there is a detected existing tag (regardless of access)site-kit-wp/assets/js/modules/analytics/hooks/useExistingTagEffect.js
Lines 79 to 84 in f3eea27
if ( existingTag ) { if ( existingTagPermission && existingTagAccountID ) { // There is an existing Analytics tag, select it. setAccountID( existingTagAccountID ); selectProperty( existingTag ); } - Leave existing GTM-related logic alone
Test Coverage
- Update
assets/js/modules/analytics/hooks/useExistingTagEffect.test.js
to cover this change in logic
Visual Regression Changes
- N/A
QA Brief
- Install and activate Site Kit plugin but don't set it up
- Install the tester plugin and use the
Place Analytics existing tag
feature - Check that a frontend page has the GA tag inserted in the page
- Setup Site Kit
- Connect the Analytics module
- Check that a frontend page still only has the GA tag inserted by the tester plugin and a second one has not been inserted too
Changelog entry
- Fix bug where Analytics snippet could still be placed when an existing snippet was already present in the frontend.