• Closed by: Anonymous Submitter
  • Closed on:
  • Reason: Not a bug

Ticket #21441 - Google Analytics does not work with "scripts attribute: defer"

Hello,

Took me a while to find out why GA did not work anymore.

But I found it.
To make our site a little faster I activated in the theme-settings –> scripts attribute: defer

I tried Async first but if i select that, the script to put things into the shopping cart from the category-page does not work and the buttons keep spinning.

So I tried “defer”

@ questions:

Is there a workaround to use “defer” and also to have the GA still getting information?
We use a module called: Premium Google Analytics Enhanced Ecommerce

Or would what is your advise? Maybe just use scripts attribute: none ?
Does it make much difference in page-loading speed?

Comments

Fred 03 May 2021, 17:50

Hi, Marianne van der Sluis.
1. You can read more about defer an async option here https://flaviocopes.com/javascript-async-defer/ all depends on your modules set. Some modules requires one option some another one. Just try which one will work for you
2. As for the Google Analytics, one of possible solutions is to enable Native Footer option in the Theme Settings. You can find more information in the documentation https://alysum5.promokit.eu/promokit/documentation/pkthemesettings/#footer

Marianne van der Sluis 04 May 2021, 13:25

Hi Fred,
Thank you for the response.

If I enable the native footer, i can see where i can do that, why do i do that? Do I then hook the google analytics module to the footer?

Only enabling the native footer, in combination with the use of the module and scripts attribute: defer did not make a diffrence, I then still get no results in Google Analytics

Marianne van der Sluis 04 May 2021, 16:56

scripts attribute: defer
–> Google analytics script does not work
scripts attribute: async
–> add to cart script from category-page does not work

How can the native footer help with a workaround?

Fred 04 May 2021, 17:21

1. try to select “none” option
2. From the documentation

Native Footer — this option enable native prestashop footer hook "displayFooter". 
Sometimes this option can be useful because some modules use this hook to output technical information.

For example "whatsappchat" module outputs it's CSS, JS and HTML markup what is a wrong way.
Correct way in this case is to hook CSS/JS into "header" hook, and HTML markup into "displayBeforeBodyClosingTag" hook.
Marianne van der Sluis 04 May 2021, 17:25

OK I’ll keep it on “none”

“Native Footer — this option enable native prestashop footer hook “displayFooter”.
Sometimes this option can be useful because some modules use this hook to output technical information.” .. i did read that but it does not help me understand what i can do
–> do i activate this option and then hook the Analytics module to that location?

Fred 05 May 2021, 10:28

I assume the Analytics module already hooked there, that’s why I ask to try to enable Native Footer option

Marianne van der Sluis 05 May 2021, 10:46

Yes I don’t know if it hooked there but when I activated the native footer in combination with scripts attribute: defer
Google analytics script did not work. Just tested again

Fred 05 May 2021, 12:16

Have you tried to reset your analytics module?

Marianne van der Sluis 05 May 2021, 12:27

Yes and updated to the latest version.

Fred 06 May 2021, 12:04

I have checked out your configuration and everything seems to be correct - https://take.ms/qW5Qt

Please check out the module documentation, maybe you will find some suggestions there https://docs.reactioncode.com/en/modules/prestashop/premium-google-analytics-enhanced-ecommerce/