Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Google Analytics and Segment initializers only once within the head section … #57

Conversation

nnande
Copy link
Contributor

@nnande nnande commented Jan 4, 2021

…of frontend layout view.

Currently initializer.js scripts both for GA and Segment can be included multiple times, once for each <meta> occurrence within a HTML page body (keyword, description, viewport, charset etc.)

Considering Segment integration, this can produce JS console errors (as can be seen below, there is a safeguard against such a case in the segment.js source code however still it's a good practice not to include obsolete JS snippets.

analytics.js source

<script type="text/javascript">
  (function(){
    ...
    // If the snippet was invoked already show an error.
    if (analytics.invoked) {
      if (window.console && console.error) {
        console.error('Segment snippet included twice.');
      }
      return;
    }
    ...    

I am not sure if some similar safeguard mechanism exists for Google Analytics.

@damianlegawiec damianlegawiec merged commit 7fd4c52 into spree-contrib:master Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants