webmatch / WbmTagManager

Shopware 5 Plugin for Google Tag Manager integration and dataLayer configuration
27 stars 18 forks source link

tracking of user data on cached pages #20

Closed uehler closed 5 years ago

uehler commented 5 years ago

if you create a tag, which tracks personal data on cached pages, you will track wrong data.

detail page for example: If you are the first customer, your personal data will be added to the tag. Because the page is cached, the tag with your data is also cached and will be served to all customers who load that page. If the first customer is not logged in, the tag will track empty data for all page views.

Is there any chance to track dynamic data with this tag manager?

dneustadt commented 5 years ago

Hello uehler,

you accurately described one of the major hurdles when it comes to developing plugins for Shopware. The usual solution to this problem is to use the cache-breaking widget controllers. As you may know, I recently added a feature to add modules for custom dataLayers. I just released a new version that now supports widget controllers as custom modules.

In the following example we want to track the first name of the logged in customer. As a "carrier" for dataLayer push we will use the checkout/info endpoint. First, make sure that the endpoint is not being cached. So possibly remove from widgets/checkout controller from the cached controller list. Add a new module with the key widgets_checkout_info. Afterwards you can go ahead and configure the dataLayer for the new module. To get an idea of the variables you can use within the dataLayer see the template of the endpoint under themes/Frontend/Bare/widgets/checkout/info.tpl

checkout_info

The dataLayer push for widget views will be prepended directly before the corresponding markup, so it possibly won't be part of the first push within the head tag but will appear wherever the widget was inserted. I hope this helps.

I won't upload that new version the Shopware Community Store just now. It would help a lot if you would be willing to give this a try first and tell me if this version solved the issue.

uehler commented 5 years ago

ok great, we will test it on monday and give you feedback

uehler commented 5 years ago

Hi @dneustadt,

I just tested your changes and it looks good so far, but there are a lot of executions of the window.dataLayer.push on detail and listing (screen from detail)

bildschirmfoto 2018-10-16 um 15 38 47 1

In our custom theme its even worse.

I did the same steps like you and tested Shopware 5.2.27 with custom theme based on the bootstrap theme and Shopware 5.3.7 with default theme

dneustadt commented 5 years ago

Thanks for the feedback. I just drafted a new release (still 3.2.0) that includes according changes. That should fix the issue with identical dataLayer tags being prepended on multiple Widget PostDispatch events.

uehler commented 5 years ago

yes, that problem is fixed

thank you very much!