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

Magento 2.2.5: Google Analytics not added to head correctly #16497

Closed
WalterSmulders opened this issue Jul 3, 2018 · 35 comments
Closed

Magento 2.2.5: Google Analytics not added to head correctly #16497

WalterSmulders opened this issue Jul 3, 2018 · 35 comments
Assignees
Labels
Component: GoogleAnalytics Event: mm18hr Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@WalterSmulders
Copy link

WalterSmulders commented Jul 3, 2018

Preconditions

  1. Magento version 2.2.5
  2. PHP 7.1
  3. MariaDB 15.1
  4. NginX 1.13.8

Steps to reproduce

  1. Enable Google Analytics trough admin Stores -> Configuration -> Sales -> Google API
  2. Fill in account number
  3. Save configuration
  4. Clear cache

Expected result

  1. Google Analytics JavaScript should be loaded on the frontend

Actual result

  1. Google Analytics isn't added at all on the frontend.

I managed to find the problem myself. In Magento 2.2.5 the file Magento_GoogleAnalytics/view/frontend/layout/default.xml was changed.

It now injects the Google Analytics block trough:
<referenceContainer name="head.additional">

But head.additional isn't a container but a block.

The fix I am using is to create a file:
app/design/frontend/-THEME VENDOR-/-THEME NAME-/Magento_GoogleAnalytics/layout/override/base/default.xml

with following content:

<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="head.additional"> <block class="Magento\GoogleAnalytics\Block\Ga" name="google_analytics" as="google_analytics" template="Magento_GoogleAnalytics::ga.phtml"/> </referenceContainer> </body> </page>

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jul 3, 2018
@magento-engcom-team
Copy link
Contributor

Hi @WalterSmulders. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me {$VERSION} instance

where {$VERSION} is version tags (starting from 2.2.0+) or develop branches (2.2-develop +).
For more details, please, review the Magento Contributor Assistant documentation.

@WalterSmulders do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@WalterSmulders WalterSmulders changed the title Google Analytics not added to head Magento 2.2.5: Google Analytics not added to head correctly Jul 3, 2018
@engcom-backlog-nickolas engcom-backlog-nickolas added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Progress: needs update labels Jul 4, 2018
@engcom-backlog-nickolas
Copy link

@WalterSmulders, thank you for your report. I've checked this issue on Magento 2.2.5, and google-analytics.js loads for me on storefront just fine.
source
js

@ishakhsuvarov
Copy link
Contributor

Adding link to the Pull Request where this was introduced: #14293

@engcom-backlog-nickolas

@WalterSmulders, we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.

@eamontaylor
Copy link

eamontaylor commented Sep 8, 2018

Did this issue ever get resolved as i'm having the same issue?

@DanielRuf DanielRuf reopened this Sep 9, 2018
@DanielRuf
Copy link
Contributor

Probably not. So before this it was a block and now it is a container?

This would be a breaking change which affects all who overwrite default.xml (which is the case when you create a custom theme or extend theme files).

@eamontaylor
Copy link

eamontaylor commented Sep 9, 2018

@DanielRuf Thanks. I think the default theme has changed, i've inherited a project, and updated it from 2.1.8 to 2.2.5 do you know what the fix is for this?

@DanielRuf
Copy link
Contributor

The fix for us who have a custom or other theme based on Blank / Luma have to port the changes to the overwritten / changed files. Good to know, will have to check this also for one of our projects.

@DanielRuf
Copy link
Contributor

Basically doing a diff (changing block to container).

@DanielRuf
Copy link
Contributor

We have to check here if 2.2.5 or a previous release introduced this change.

@ghost ghost self-assigned this Sep 10, 2018
@ghost
Copy link

ghost commented Sep 10, 2018

Hi @DanielRuf seem this issue was fixed in 2.2.5 but if you have a custom theme you need overwrite odefault.xml to origin luma or blank file ?
Hi @eamontaylor Did you solve your problem ?

@eamontaylor
Copy link

Hi I've updated the following default.xml file it's not working so i guess it's not the right path.

app/design/frontend/-THEME VENDOR-/-THEME NAME-/Magento_Theme/layout/default.xml

<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="head.additional"> <block class="Magento\GoogleAnalytics\Block\Ga" name="google_analytics" as="google_analytics" template="Magento_GoogleAnalytics::ga.phtml"/> </referenceContainer> <referenceBlock name="reviews.tab" remove="true" /> <referenceBlock name="product.review.form" remove="true" /> <referenceBlock name="product.info.review" remove="true" /> <referenceBlock name="category.product.addto" remove="true" /> <referenceBlock name="related.post.tab" remove="true" /> </body> </page>

What file exactly do I need to update?

@ghost
Copy link

ghost commented Sep 10, 2018

@eamontaylor this is right path -> app/design/frontend/-THEME VENDOR-/-THEME NAME-/Magento_GoogleAnalytics/layout/override/base/default.xml

@eamontaylor
Copy link

eamontaylor commented Sep 10, 2018

@engcom-backlog-nazar nope this doesn't work for me.

Upgraded, Compiled, Deployed, Cleared cache and still nothing,

@ghost
Copy link

ghost commented Sep 10, 2018

@eamontaylor did you clear pub static files?

@WalterSmulders
Copy link
Author

@eamontaylor If you correctly override the XML it will work, I have this fix in place in several live Magento installs

@ghost
Copy link

ghost commented Sep 10, 2018

@eamontaylor you may do something wrong, i do this with custom theme and it works perfectly.

@ghost
Copy link

ghost commented Sep 10, 2018

@DanielRuf Can i close issue ? or leave open, until somebody change name from container to block ?

@eamontaylor
Copy link

Do i need to change refernceContainer to referenceBlock?

@ghost
Copy link

ghost commented Sep 10, 2018

@eamontaylor yes but seems it's not solve your problem.

@eamontaylor
Copy link

@engcom-backlog-nazar Thanks, i've tried everything you've suggested but still no joy.

@eamontaylor
Copy link

@DanielRuf Yep cleared the caches again and that seems to of sorted it thanks everyone.

@hostep
Copy link
Contributor

hostep commented Sep 10, 2018

I believe @WalterSmulders has a point here.

  1. head.additional is created as a Block
  2. Is being referenced correctly in the catalog module
  3. Is being incorrectly referenced as a container in the google analytics module

The strange thing is, that this seems to work perfectly fine. So you can reference a block using referenceContainer which is not what I expected.

I'm not sure if customisations can break this somehow, but I think it would be best that the referenceContainer is replaced with referenceBlock in the google analytics module.

@ghost ghost added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Component: GoogleAnalytics Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development and removed Progress: needs update labels Sep 11, 2018
@ghost
Copy link

ghost commented Sep 11, 2018

@WalterSmulders , thank you for your report.
We've acknowledged the issue and added to our backlog.

@ghost ghost removed their assignment Sep 11, 2018
@WalterSmulders
Copy link
Author

@engcom-backlog-nazar happy to hear the bug is acknowledged and it will be fixed

@sambolek
Copy link
Contributor

#mm18hr

@slavvka
Copy link
Member

slavvka commented Oct 3, 2018

Hi @WalterSmulders. Thank you for your report.
The issue has been fixed in #18290 by @sambolek in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.1 release.

@slavvka slavvka added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Oct 3, 2018
@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Oct 4, 2018
@magento-engcom-team
Copy link
Contributor

Hi @WalterSmulders. Thank you for your report.
The issue has been fixed in #18375 by @sambolek in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.8 release.

Amadeco pushed a commit to Amadeco/elasticsuite that referenced this issue Jan 18, 2019
Good afternoon,

Just one typo error with the script declaration "Smile_ElasticsuiteTracker::js/tracking.js" (anyway, it include correctly this javascript file).

And some inconsistents with the declaration of head.additional which is a block not a container 
(Same problem on Magento_GoogleAnalytics, this is not solved in my version of Magento 2.3 - magento/magento2#16497)

Personally, I would rather move the script tracking.js into the before.body.end before block smile.tracker.page.base.
I think you recommends to place it in the <head>, so if someone aborts a load of the page, the script might get executed.
"It helps you to accurately record traffic stats because your header scripts are loaded earlier than any other scripts on your page."

Cheers,
Ilan PARMENTIER
@Rickertje
Copy link

I am on 2.2.7. I experience the exact same issue with the Adwords block (... while the Analytics block is working for me). Any comments on that?

@Rickertje
Copy link

@WalterSmulders can you please make a comment on this?

@WalterSmulders
Copy link
Author

@WalterSmulders can you please make a comment on this?

I did not experience this issue. I recommend to see if the fix I gave in the opening post can be applied to the Adwords block, furthermore I think it's wise to treat this as a separate issue since this one is closed and likely contains a other part of the code.

@Rickertje
Copy link

Rickertje commented May 8, 2019

@WalterSmulders ok thanks I wil investigate and post a new issue if necessary

@pioneerathletics
Copy link

The Google Analytics code is still not being properly added to the head in 2.2.8. I applied the fix in 2.2.7 as a layout extension - theme-dir/Magento_GoogleAnalytics/layout/default and it worked properly in 2.2.7 after it was applied. I upgraded to 2.2.8 and removed the layout customization, but now the code is not being added properly as it was before. Also, I have cleared all my caches but that hasn’t solved my issue.

@pioneerathletics
Copy link

I resolved my issue. It was due to another layout extension I had within theme-dir/Magento_Catalog/layout/default.xml. I didn't realize that the latest fix in 2.2.8 referenced that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: GoogleAnalytics Event: mm18hr Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests