Problem/Motivation
Currently, when events are being triggered they are being stored in the current user's tempstore. When a anonymous user triggers these events we'll start a session which will impact the page caching significantly and slows down the entire experience. In most Commerce situations this is probably no biggy since most stores will probably use logged in users. We're on the other hand are allowing anonymous users to order products.
Steps to reproduce
Trigger a event like productDetailViews as a anonymous user and note that you get a session cookie assigned.
Proposed resolution
Looking at the module, I think the only reason why we're using tempstore is because there is a route endpoint which exposes the events as a JSON response, allowing JS to fetch these events and sending them client-side to GTM. I'm wondering if there would be any downside of sending these events server-side, but I'm not familiar enough with GTM to know the pros/cons. If this is possible, we'd be able to store the events within the same request which would eliminate the need for tempstore.
Remaining tasks
Discovery of possibility to send events to GTM server-side.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Issue fork commerce_google_tag_manager-3308307
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3308307-prevent_tempstore compare
- 3308307-prevent-usage-of changes, plain diff MR !6
Comments
Comment #2
JeremyFrench CreditAttribution: JeremyFrench at Full Fat Things commentedThe issue has manifested on a site I am working on in a different way. For whatever reason the page is being cached with the view product on, and when a subsequent user tries to get the data they will not receive a view item event.
I think we can serve in the same request and in a proof of concept I have it working. Once a user has started the checkout flow they will have a session and the issue of caching isn't so important but for the view_item at least we should allow this to work anonymously and with caching.
Comment #5
josegracia CreditAttribution: josegracia at Hiberus commentedI propose to use just tempstore just in an opened session. Also the events are stored in a static property in the Event Storage Service so we can send it to the JS, then push those events to dataLayer.
In incognito we can keep using the controller to get the events but avoiding to use tempstore so we dont miss the static cache.