elgentos / magento2-serversideanalytics

Server side analytics for Magento 2
MIT License
64 stars 21 forks source link

Missing purchase events in case of adblock #37

Closed indykoning closed 8 months ago

indykoning commented 12 months ago

Because of https://github.com/elgentos/magento2-serversideanalytics/blob/879f2a95a0177da11d2e3cfec863dc65c7697850/Observer/SendPurchaseEvent.php#L75 Purchase events will no longer be fired at all once the customer placing the order does not have a session id in their cookie.

This is possible because a customer blocks GTM causing their GA id and GA session ids to never be created. Previously this was solved for the GA id by creating a temporary id

INFO: Google Analytics cookie not found, generated temporary value: 000000000.000000000

https://github.com/elgentos/magento2-serversideanalytics/blob/879f2a95a0177da11d2e3cfec863dc65c7697850/Plugin/SaveGaUserDataToDb.php#L80

However this same process does not exist for the session id

I'm afraid i do not know wether we should send the event with an empty session id or a generated session id

WouterSteen commented 12 months ago

You are absolutely right!

WouterSteen commented 12 months ago

I think we need to create a fake one. But ive asked my GA guy if this is correct.

WouterSteen commented 12 months ago

        if ($gaSessionId === null) {
            $gaSessionId = random_int((int)1E01, (int)1E010);
            $this->logger->info('Google Analytics cookie not found, generated temporary value: ' . $gaSessionId);
        }

This would be it then

WouterSteen commented 11 months ago

Merged!

WouterSteen commented 8 months ago

Does this work for you @indykoning ? For us this is working in 2 projects!

indykoning commented 8 months ago

I'm seeing a lot of fallback session ids in some of our projects so by the looks of it it is working perfectly! 🚀