Server side analytics for Magento 2

Overview

Server Side Analytics for Magento 2

This extension aims to solve the problem of discrepancies between Magento revenue reports and the revenue reports in Google Analytics.

That problem arises due to the fact that a certain number of people close the browser window before returning to Magento's success page. Since Google Analytics is Javascript based, and thus client based, the GA Purchase Event will not be fired and the order will not be registered in Analytics.

Another reason why this problem arises is that people decide to pay at a later point in time through a different platform (like the PSP's), using a link in an email for example.

Caveats

  • This extension disables the GA JS Purchase Event on the success page altogether. It will however track the pageview.
  • This extension only tracks paid orders (it fires on sales_order_payment_pay). Non-paid orders will never show up in Analytics. This is our current clients' use case, mileage may differ. PR's for code to also track non-paid orders are welcomed.

Further info

  • Compatible with GA Measurement Protocol version 1;
  • Debugging is enabled when Magento is in developer mode. See var/log/system.log for the log;
  • Exceptions will be logged to var/log/exceptions.log;
  • The products in the payload are retrieve on invoice-basis, not on order-basis;
  • An event has been added for you to add or overwrite custom fields to products in the purchase event; elgentos_serversideanalytics_product_item_transport_object;
  • An event has been added for you to add or overwrite fields to tracking data in the purchase event; elgentos_serversideanalytics_tracking_data_transport_object;
  • Testing can be done by dispatching test_event_for_serversideanalytics with a $payment (\Magento\Sales\Order\Payment) object in the payload;
Comments
  • Add support for GA4

    Add support for GA4

    This PR will add an option to either enable UA, enable GA4 or enable both at the same time (although they would use the same tracking id which seems to work from the testing i've done) Config paths have been kept as is so it should not break existing installations (so long as no plugins have been made on the GAClient)

    The old Model/GAClient had been renamed to Model/UAClient since this is the more appropriate name, other than that it shouldn't have changed.

    opened by indykoning 7
  • Not working with PHP 8.1

    Not working with PHP 8.1

    Latest version is not working with Magento 2.4.4 and PHP 8.1

    [09-Aug-2022 08:09:13 UTC] PHP Fatal error: During inheritance of IteratorAggregate: Uncaught Exception: Deprecated Functionality: Return type of TheIconic\Tracking\GoogleAnalytics\Parameters\CompoundParameterCollection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/domains/domain.nl/releases/20220809065139/vendor/theiconic/php-ga-measurement-protocol/src/Parameters/CompoundParameterCollection.php on line 95 in /var/domains/domain.nl/releases/20220809065139/vendor/magento/framework/App/ErrorHandler.php:61

    opened by JoostWan 5
  • Fixed issue with random_int

    Fixed issue with random_int

    The method random_int expects int as parameters. 1E8 and 1E9 result in floats, so they have to be cast. Otherwise, the whole thing runs into a type error

    CleanShot 2022-10-10 at 10 33 42@2x
    opened by DavidLambauer 3
  • Some transactions are recorded twice

    Some transactions are recorded twice

    Not sure how to reproduce (yet), but some transactions are logged twice in Google Analytics. Many transactions also appear twice in the system.log with a few seconds apart, but most of them are shown only once in Google Analytics. So there might be some filtering/deduplication happening on the Google side.

    [2021-02-04 09:31:35] main.INFO: elgentos_serversideanalytics_requests:  ["https://ssl.google-analytics.com/collect?ti=16000000118&tr=175&tt=30.37&ts=0.0000&ta=B2C&v=1&tid=UA-XXX-2&uip=92.xx.xx.xx&cid=xxx.xxx&dp=%2Fcheckout%2Fonepage%2Fsuccess%2F&pa=purchase&ec=Checkout&ea=Purchase&t=event&pr1id=sku.42&pr1nm=Product&pr1pr=175.0000&pr1qt=1.0000"] []
    [2021-02-04 09:31:36] main.INFO: elgentos_serversideanalytics_requests:  ["https://ssl.google-analytics.com/collect?ti=16000000118&tr=175.0000&tt=30.3700&ts=0.0000&ta=B2C&v=1&tid=UA-XXX-2&uip=92.xx.xx.xx&cid=xxx.xxx&dp=%2Fcheckout%2Fonepage%2Fsuccess%2F&pa=purchase&ec=Checkout&ea=Purchase&t=event&pr1id=sku.42&pr1nm=Product&pr1pr=175.0000&pr1qt=1.0000&pr1ps=27432"] []
    

    As you can see, both are very similar with a few tiny differences:

    Rounding is different:

    tr=175
    tr=175.0000
    
    tt=30.37
    tt=30.3700
    

    Item position is missing in the first:

    pr1qt=1.0000"
    pr1qt=1.0000&pr1ps=27432"
    

    Again, not really sure if this is causing the issue or just coincidence. But leaving here for reference.

    opened by barryvdh 3
  • Error 'For Analytics object, you must specify a value to be set for setAffiliation' while creating CreditCard payment with Stripe

    Error 'For Analytics object, you must specify a value to be set for setAffiliation' while creating CreditCard payment with Stripe

    When an order is created with Creditcard, this message occurs:

    For Analytics object, you must specify a value to be set for setAffiliation

    I think that can only occur when $order->getStoreName() returns null. With iDeal this doesn't happen, but it does with CreditCard. Perhaps because the order is captured directly?

    opened by barryvdh 2
  • Generator fallback ClientID

    Generator fallback ClientID

    This might be depending on your use case, but if a customer has disabled Google Analytics (eg using Ublock or similar extensions), the _ga cookie is never set. This will prevent the order from dispatching to GA Measurement Protocol.

    I understand that it's generally preferred to use the actual user/client ID but this is not always possible. In our case, we would rather still record the purchase in Analytics, so that the revenue is correct, even though it cannot be traced to any marketing action.

    opened by barryvdh 0
  • Save GA User Id with GraphQL

    Save GA User Id with GraphQL

    Excuse the mess of commits, feel free to squash 😅 This allows the ga_user_id to be saved to the quote by a headless frontend via GraphQL

    This can then be passed on to the order to provide serverside tracking for this client id. This gets picked up in https://github.com/elgentos/magento2-serversideanalytics/blob/master/Observer/SaveGaUserId.php#L97 which was accidentally in there by accident.

    opened by indykoning 1
  • Add ga_sent_at to prevent duplicates

    Add ga_sent_at to prevent duplicates

    This prevents https://github.com/elgentos/magento2-serversideanalytics/issues/5 from happening, even if its fault lies outside this module.

    If for any reason, an even is already sent, it should not happen again. Otherwise the order might be tracked twice.

    opened by barryvdh 6
Releases(1.0.1)
  • 1.0.1(Sep 20, 2022)

    Use 8ctopus/php-ga-measurement-protocol fork for PHP 8.1 compat

    Full Changelog: https://github.com/elgentos/magento2-serversideanalytics/compare/1.0.0...1.0.1

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Sep 15, 2022)

    Finally we have GA4 support, thanks to @indykoning's hard work :partying_face:

    What's Changed

    • Create LICENSE by @JeroenBoersma in https://github.com/elgentos/magento2-serversideanalytics/pull/13
    • Add support for GA4 by @indykoning in https://github.com/elgentos/magento2-serversideanalytics/pull/14

    New Contributors

    • @JeroenBoersma made their first contribution in https://github.com/elgentos/magento2-serversideanalytics/pull/13

    Full Changelog: https://github.com/elgentos/magento2-serversideanalytics/compare/0.1.10...1.0.0

    Source code(tar.gz)
    Source code(zip)
  • 0.1.8(May 2, 2022)

    What's Changed

    • Prevent Deprecated functionality exception by @indykoning in https://github.com/elgentos/magento2-serversideanalytics/pull/8

    New Contributors

    • @indykoning made their first contribution in https://github.com/elgentos/magento2-serversideanalytics/pull/8

    Full Changelog: https://github.com/elgentos/magento2-serversideanalytics/compare/0.1.7...0.1.8

    Source code(tar.gz)
    Source code(zip)
  • 0.1.7(Mar 31, 2022)

    What's Changed

    • Only enable debug mode when it's enabled by @royduin in https://github.com/elgentos/magento2-serversideanalytics/pull/7

    New Contributors

    • @royduin made their first contribution in https://github.com/elgentos/magento2-serversideanalytics/pull/7

    Full Changelog: https://github.com/elgentos/magento2-serversideanalytics/compare/0.1.6...0.1.7

    Source code(tar.gz)
    Source code(zip)
  • 0.1.6(Feb 9, 2021)

Owner
elgentos ecommerce solutions
Magento 2 & Laravel boutique e-commerce agency
elgentos ecommerce solutions
A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc). Based on the difflib implementation in Python

PHP Diff Class Introduction A comprehensive library for generating differences between two hashable objects (strings or arrays). Generated differences

Chris Boulton 708 Dec 25, 2022
You can handle iOS Application Subscription Server Side with Laravel.

Auto Renewing Subscriptions for iOS Apps with Laravel This repository help you to handle iOS Application Subscription on server side. It provides Save

Ajay Thakkar 2 Jun 29, 2022
run user analytics within your system and track user data inside your database.

WP Local Analytics plugin. run user analytics within your system and track user data inside your database. Installing Go to the plugin page from the W

Gary 5 Dec 21, 2022
Google Analytics Measurement Protocol Package for Symfony

Google Analytics Measurement Protocol Package for Symfony. Supports all GA Measurement Protocol API methods.

Four Labs 31 Jan 5, 2023
Columnar analytics for PHP - a pure PHP library to read and write simple columnar files in a performant way.

Columnar Analytics (in pure PHP) On GitHub: https://github.com/envoymediagroup/columna About the project What does it do? This library allows you to w

Envoy Media Group 2 Sep 26, 2022
Magento-Vagrant-Puppet-Nginx - Installs magento and a nginx server

Magento-Vagrant-Puppet-Nginx Installs Magento MySQL PHP PHP-FPM Nginx n98-magerun Setup git submodule init git submodule update vagrant up Modify pupp

Christian Münch 61 Aug 10, 2022
A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2

Simple Import / Export tool A tool that allows to quickly export data from Magento 1 and Magento 2 store and import it back into Magento 2. Table data

EcomDev B.V. 51 Dec 5, 2022
For server-to-server comms from PHP to CloudKit.

CloudKit-PHP Today I found this fantastic gist by Mauricevb that demonstrates how to communicate with CloudKit from PHP. I already had a previous proj

Tim Oliver 1 Oct 14, 2021
A plugin that allows you to hear the sound "Welcome to the server!" when you join the server by NhanAZ for PocketMine-MP

General A plugin that allows you to hear the sound "Welcome to the server!" when you join the server by NhanAZ for PocketMine-MP Contacts You can cont

NhanAZ's PocketMine-MP Plugins 10 Sep 27, 2022
Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)

COPS COPS stands for Calibre OPDS (and HTML) Php Server. See : COPS's home for more details. Don't forget to check the Wiki. Why ? In my opinion Calib

Sébastien Lucas 1.3k Jan 1, 2023
Php-rpc-server - JSON RPC server implementation for PHP.

JSON RPC Server implementation for PHP. The json-rpc is a very simple protocol. You can see this by reading the protocol specification. This library i

null 4 Sep 28, 2022
This project processes a small database with php all on a web server. This project uses XAMPP to run the web server and the database.

PHP-introduction This project processes a small database with php all on a web server. This project uses XAMPP to run the web server and the database.

Tyler Jacques 1 Jan 6, 2022
EXT:server-timing adds Server-Timing Header with usefull information

EXT:server_timing - see your performance installation composer require kanti/server-timing at the moment there is nothing to configure Server timings

Matthias Vogel 4 Oct 26, 2022
A Simplistic Plugin to Implement Server Claims to your Minecraft: Bedrock Server.

Claims This plugin allows administrators to create, edit, list, and teleport to land claims on a PocketMine server. These claims have a variety of cus

Santana 5 Jun 10, 2023
This Magento 2 extension integrates EasyTranslate into Magento 2.

EasyTranslate Magento 2 Connector This Magento 2 extension integrates EasyTranslate into Magento 2. Mind that you need to have an account with EasyTra

Easytranslate ApS 0 Oct 7, 2022
Magento-Functions - A Resource of Magento Functions

Magento-Functions A Resource of Magento Functions Table of Contents Category Product User Cart Checkout General Account [Working w/ URL's] (#urls) Cat

Bryan Littlefield 28 Apr 19, 2021
Magento - Magento Community Editions

Magento Community Edition /// THIS REPOSITORY IS DEPREACTED /// 1.9.4.1 will be the last version update. Please switch over to OpenMage! Either to the

FireGento e. V. 107 Oct 17, 2022