Google Analytics module

      Google Analytics module


        Article Summary

        Buckaroo has developed its own Google Analytics module, which serves as an additional plugin for the Buckaroo Magento 2 platform. This powerful plugin significantly improves tracking allocation.

        Standard Google Analytics Tracking often struggles to properly attribute the conversion source when transactions occur across different browsers or devices. For example, 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. As a result, the success page is displayed on yet another device.

        To effectively address this scenario, our module tracks the Google Client ID associated with the order. Subsequently, we can 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 behavior across various devices and browsers. With this solution, you can now 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.
        Magento2_download_button

        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

        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.