buckaroo/magento2analytics

Buckaroo Magento2 Analytics extension

v1.1.1 2023-06-13 09:01 UTC

README

68747470733a2f2f7777772e6275636b61726f6f2e6e6c2f6d656469612f333437382f6d6167656e746f325f676f6f676c65616e616c79746963735f69636f6e2e706e67

Buckaroo Magento2 Analytics extension

Latest release

Index

Installation and configuration

composer require buckaroo/magento2analytics
php bin/magento module:enable Buckaroo_Magento2Analytics
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy

Usage

General information

GA Tracking does not allocate properly the conversion source when the transaction happens cross-browser or cross-device. Visitor lands on the website from an ad campaign, goes through the order process, but the payment process takes place on a different device or browser and success page is also displayed in a different device In order to handle this situation, we track the Google Client ID against the order and we can trigger an enriched version of the tracking code in the success page, by adding the clientId parameter.

Javascript / GTM

clientId value is passed as a parameter in the URL of the success page, part of the redirect process. This can be extracted and used in the javascript code that triggers the GA/UA/GTM/other event for the conversion. Standard structure of the URL is the following: /checkout/onepage/success/?clientId=****/

and the clientId can be extracted:

    try{
        currentPageUrl = window.location.href;
        myClientId = currentPageUrl.split('clientId=')[1].split('/')[0];
    } catch(error) {
        myClientId = '';
    }

and sent to GA/UA part of the tracking code:

    ga('create', 'UA-XXXXX-Y', {
        'storage': 'none',
        'clientId': myClientId
    });

Serverside

The information related to clientId is also stored in the database. And this can be used on the server side level, via the Model repository Buckaroo\Magento2Analytics\Model\AnalyticsRepository using the quoteId:

use Buckaroo\Magento2Analytics\Model\AnalyticsRepository;
use Magento\Framework\Exception\NoSuchEntityException;

class MyCustomViewModel
{
    public function __construct(
        AnalyticsRepository $analyticsRepo
    ) {
        $this->analyticsRepo = $analyticsRepo;
    }

    public function getClientId($quoteId)
    {
        $clientId = null;
        try {
            $clientIdData = $analyticsRepo->getByQuoteId($quote->getId());
            return $clientIdData->getClientId();    
        } catch(\Exception $e) {
            throw new NoSuchEntityException(__('ClientId not found for quoteId' . $quoteId ));
        }
        
    }
}

Features

Dynamic URL Parameters on Success Page Based on Cookies:

• This new feature enables you to add unlimited URL parameters on the success page, utilizing information stored in cookies. This is a significant addition that enables more granular tracking of customer activity and success page interactions, leading to more precise and actionable analytics data.

• The new module is designed for easy use: simply add another pair of cookie name, URL parameter, and the replace regex if you want to extract only a portion of the text. This flexibility allows for precise control over what information is captured and used in your URL parameters.

How to Use:
To utilize this feature:
1. Go to the Buckaroo Magento2_Analytics module settings (Stores → Settings → Configuration → Sales → Buckaroo → GA Tracking Options).

Google_Analytics_Configuration

2. Enable GA Tracking.
3. Add a new pair consisting of the cookie name and the URL parameter that you wish to set based on the cookie's value.
4. (Optional) If you only need to extract a specific part of the text, provide a replace regex.
5. Save the settings.
6. The module will automatically handle the rest, setting the URL parameters on your success page based on the specified cookies.

Contribute

We really appreciate it when developers contribute to improve the Buckaroo plugins. If you want to contribute as well, then please follow our Contribution Guidelines.

Versioning

68747470733a2f2f7777772e6275636b61726f6f2e6e6c2f6d656469612f333438302f6d6167656e746f5f76657273696f6e696e672e706e67

  • MAJOR: Breaking changes that require additional testing/caution.
  • MINOR: Changes that should not have a big impact.
  • PATCHES: Bug and hotfixes only.

Additional information

Please note:
This file has been prepared with the greatest possible care and is subject to language and/or spelling errors.