magepal / magento2-google-tag-manager

Google Tag Manager is a user-friendly, yet powerful and cost-effective solution that is a must-have integration for every Magento store. It simplifies the process of adding and managing third-party JavaScript tags. With dozens of custom events and hundreds of data points our extensions the #1 GTM solution for Magento.
https://www.magepal.com/google-tag-manager.html
259 stars 89 forks source link

Js Error "Uncaught TypeError" with Varnish and GDPR enabled #63

Closed ChrHartwig closed 4 years ago

ChrHartwig commented 4 years ago

Magento version #:

2.2.9

Edition (EE, CE, OS, etc):

CE

Expected behavior:

No JS-Errors on Pageload

Actual behavior:

Get following JS Error: datalayer.js:69 Uncaught TypeError: Cannot read property 'get' of undefined at isTrackingAllowed (datalayer.js:69) at datalayer.js:107 at main.js:31 at Object.execCb (require.js:1650) at Module.check (require.js:866) at Module. (require.js:1113) at require.js:132 at require.js:1156 at each (require.js:57) at Module.emit (require.js:1155)

-> $.mage.cookies.get is undefined in this case

Preconditions

Steps to reproduce:

  1. Go to Home Page and Reload

Important: This only happens with Varnish. This does not happens with Magento's built in cache.

srenon commented 4 years ago

@Neusta-Hartwig ... Could you try adding ''mage/cookies','

define([
    'Magento_Customer/js/customer-data',
    'jquery',
    'mage/cookies',
    'underscore'
],

MagePal/GoogleTagManager/view/frontend/web/js/datalayer.js

ChrHartwig commented 4 years ago

@srenon

thx for your fix. The order of the params is important, so the final fix is:

define([ 'Magento_Customer/js/customer-data', 'jquery', 'underscore', 'mage/cookies' ]

Thank you

srenon commented 4 years ago

@Neusta-Hartwig ... Yea, I realize that I params was in the wrong order and already fixed it. This fix will be included in the next release.

Thanks for letting us know!