这是indexloc提供的服务,不要输入任何密码
Skip to content

Site Kit outputting Analytics snippet by default - on sites with existing Analytics snippets #2909

@jamesozzie

Description

@jamesozzie

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)

ex

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

  1. Manually insert an Analytics tracking snippet
  2. Install and setup Site Kit
  3. Connect the Analytics module
  4. 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
  5. Analytics snippet appears twice (one manual placement, another via SK)
  6. 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 set useSnippet to false if that is detected.

Implementation Brief

  • Update Analytics’ useExistingTagEffect to call setUseSnippet( false ) when there is a detected existing tag (regardless of access)
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Module: AnalyticsGoogle Analytics module related issuesP0High priorityType: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions