Google Analytics module

Buckaroo has developed a powerful Google Analytics module, serving as an additional plugin for the Buckaroo Magento 2 platform. This plugin significantly improves tracking allocation.

Standard Google Analytics tracking often struggles to accurately attribute the conversion source when transactions occur across different browsers or devices. For instance, a visitor may initially land on the website through an ad campaign, proceed with the order process, but complete the payment on a different device or browser. Consequently, the success page is displayed on yet another device.
To address this scenario effectively, our module tracks the Google Client ID associated with the order. This allows us to enhance the tracking code on the success page by including the clientId parameter. This ensures accurate allocation of conversions and provides valuable insights into user behaviour across various devices and browsers. With this solution, you can seamlessly optimize your Google Analytics tracking and gain a clearer understanding of your website's performance.


Installation & Configuration

You can download the module from our GitHub repository.

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

Javascript / GTM Integration

The clientId value is passed as a parameter in the URL of the success page, as part of the redirect process. This can be extracted and used in the JavaScript code that triggers the GA/UA/GTM/another event for the conversion.

  • Standard URL structure:
    • /checkout/onepage/success/?clientId=/
  • To extract the clientId:
try{
    currentPageUrl = window.location.href;
    myClientId = currentPageUrl.split('clientId=')[1].split('/')[0];
} catch(error) {
    myClientId = '';
}
  • To send clientId to GA/UA part of the tracking code:
ga('create', 'UA-XXXXX-Y', {
    'storage': 'none',
    'clientId': myClientId
});

Serverside

The clientId information is also stored in the database and can be used on the server-side 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 feature allows you to add unlimited URL parameters on the success page, utilizing information stored in cookies. This enables more granular tracking of customer activity and success page interactions, leading to more precise and actionable analytics data.

How to Use

  1. Navigate to Module Settings:
    1. Go to Stores β†’ Settings β†’ Configuration β†’ Sales β†’ Buckaroo β†’ GA Tracking Options.
  2. Enable GA Tracking:
    1. Enable the GA Tracking option.
  3. Add New Cookie-Parameter Pair:
    1. Add a new pair consisting of the cookie name and the URL parameter based on the cookie's value.
  4. Optional Regex Extraction:
    1. If needed, provide a replacement regex to extract a specific part of the text.
  5. Save Settings:
    1. Save the configuration to ensure all settings are applied.

The module will automatically handle setting the URL parameters on your success page based on the specified cookies.