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.
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.
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet">
<style>
.download-button {
background-color: #cdf564; /* Adjusted yellow-green color */
color: black;
font-weight: bold; /* Make text bold */
font-family: 'Open Sans', sans-serif; /* Use Open Sans font */
padding: 15px 32px;
text-align: center;
text-decoration: none; /* Remove underline */
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 4px;
border: none;
}
</style>
</head>
<body>
<a href="https://github.com/buckaroo-it/Magento2" class="download-button">Download</a>
</body>
</html>
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
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/other events 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
- Navigate to Module Settings:
- Go to Stores β Settings β Configuration β Sales β Buckaroo β GA Tracking Options.
- Enable GA Tracking:
- Enable the GA Tracking option.
- Add New Cookie-Parameter Pair:
- Add a new pair consisting of the cookie name and the URL parameter based on the cookie's value.
- Optional Regex Extraction:
- If needed, provide a replacement regex to extract a specific part of the text.
- Save Settings:
- 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.
Updated about 1 month ago