Prestashop module - Optimize your Google Analytics module
“Use your browser cache” for the Google Analytics module in Prestashop

If you are struggling with the optimization problem of Prestashop for Google PageSpeed Insights for the Google Analytics module (JavaScript) loaded from Google servers, I have a solution for you – the Prestashop Module!

The problem is that the ganalytics module loads the content of scripts directly from Google servers that we can not keep in the cache. In this case, we must set the HTTP headers for these files (Expires), which should be on our server and be kept for some time in the client’s browser cache. The best way to add the Expires headers is to add the following code to the .htaccess file in the main directory of your Prestashop:

    ExpiresActive On
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-javascript "access plus 1 week"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"
    ExpiresByType application/x-font-woff "access plus 1 year"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType font/opentype "access plus 1 year"
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType font/otf "access plus 1 year"
    ExpiresByType application/x-font-ttf "access plus 1 year"
    ExpiresByType application/x-font-otf "access plus 1 year"

Adding the above Expires headers will improve the PageSpeed Insights result in the test but it still does not solve the problem. To fully support the Google Analytics file from my own server, install my module which you can download below:

 

How it works?

Moduł do optymalizacji sklepu Prestashop dla Google Page Speed

The module clipartoptimizegoogleanalytics (Optymize Google Analytics) overwrites the functions of the original ganalytics module (Google Analytics for Prestashop) in such a way that the script does not download the content of JavaScript files from external sources. The module has a tool that should be set in the task schedule (cron) so that JavaScipt files are downloaded and updated on the server.

Installation guide

STEP1: Install the module with the standard tool for adding Prestashop modules: Modules and services -> Add a new module and then “Install”

STEP 2: Go to the module configuration and copy the generated URL to the CRON tool which should be called cyclically once a day. The url should be pasted into the hosting panel in the Task Scheduler (Cron) tool. Below is an example for the Ajenti panel: