Skip to content

Commit

Permalink
Merge branch '2.10.x' into 2.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet committed Nov 7, 2023
2 parents 17f69c1 + 72aa77d commit 464c21f
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 56 deletions.
20 changes: 20 additions & 0 deletions src/module-elasticsuite-tracker/Block/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ public function getBeaconUrl()
return $this->trackerHelper->getBaseUrl();
}

/**
* Retrieve tracker Rest endpoint URL
*
* @return string
*/
public function getEndpointUrl()
{
return $this->trackerHelper->getRestBaseUrl();
}

/**
* Return true if the tracker should use the (Rest) API to push its data to Magento
*
* @return bool
*/
public function isUsingAPI()
{
return $this->trackerHelper->isUsingAPI();
}

/**
* Retrieve telemetry Url
*
Expand Down
26 changes: 26 additions & 0 deletions src/module-elasticsuite-tracker/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
const CONFIG_RETENTION_DELAY_XPATH = 'smile_elasticsuite_tracker/general/retention_delay';

/**
* Using API instead of invisible pixel configuration path
* @var string
*/
const CONFIG_IS_USING_API_XPATH = 'smile_elasticsuite_tracker/general/use_api';

/**
* Anonymization status configuration path
* @var string
Expand Down Expand Up @@ -136,6 +142,26 @@ public function getBaseUrl()
return trim($this->urlBuilder->getUrl('elasticsuite/tracker/hit', ['image' => 'h.png']), '/');
}

/**
* Return the tracking Rest endpoint URL
*
* @return string
*/
public function getRestBaseUrl()
{
return $this->urlBuilder->getDirectUrl('rest/V1/elasticsuite-tracker/hit');
}

/**
* Return true if the tracker should use the (Rest) API to push its data to Magento
*
* @return bool
*/
public function isUsingAPI()
{
return $this->scopeConfig->isSetFlag(self::CONFIG_IS_USING_API_XPATH, ScopeInterface::SCOPE_STORE);
}

/**
* Return an array containing the cookie configuration
*
Expand Down
8 changes: 8 additions & 0 deletions src/module-elasticsuite-tracker/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
<field id="enabled">1</field>
</depends>
</field>
<field id="use_api" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Use the API to collect data</label>
<comment><![CDATA[If set to Yes, the tracking script will use the dedicated Rest API endpoint to send its data instead of using the legacy invisible pixel method. Useful if you have issues white-listing the tracker image URL with parameters in your frontend cache or if you customized the data collection and the tracker needs to send bigger payloads than usual.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="enabled">1</field>
</depends>
</field>
</group>
<group id="session" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Session Configuration</label>
Expand Down
1 change: 1 addition & 0 deletions src/module-elasticsuite-tracker/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<general>
<enabled>1</enabled>
<retention_delay>12</retention_delay>
<use_api>0</use_api>
</general>
<session>
<visit_cookie_name>STUID</visit_cookie_name>
Expand Down
2 changes: 2 additions & 0 deletions src/module-elasticsuite-tracker/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Enabled,Enabled
"Anonymization Delay","Anonymization Delay"
"In days. (Default is 365 days.)<br /> Tracked customer related data will be anonymized after this delay.","In days. (Default is 365 days.)<br /> Tracked customer related data will be anonymized after this delay."
"In months (default is 12 months.).<br /> Tracking data older than this will be removed each day.","In months (default is 12 months.).<br /> Tracking data older than this will be removed each day."
"Use the API to collect data","Use the API to collect data"
"If set to Yes, the tracking script will use the dedicated Rest API endpoint to send its data instead of using the legacy invisible pixel method. Useful if you have issues white-listing the tracker image URL with parameters in your frontend cache or if you customized the data collection and the tracker needs to send bigger payloads than usual.","If set to Yes, the tracking script will use the dedicated Rest API endpoint to send its data instead of using the legacy invisible pixel method. Useful if you have issues white-listing the tracker image URL with parameters in your frontend cache or if you customized the data collection and the tracker needs to send bigger payloads than usual."
2 changes: 2 additions & 0 deletions src/module-elasticsuite-tracker/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Tracking,Tracking
"Anonymization Delay","Délai d'anonymisation"
"In days. (Default is 365 days.)<br /> Tracked customer related data will be anonymized after this delay.","En jours (valeur par défaut 365 jours).<br /> Les données client collectées seront anonymisées après ce délai."
"In months (default is 12 months.).<br /> Tracking data older than this will be removed each day.","En mois (valeur par défaut 12 mois).<br /> Les données de tracking plus anciennes seront supprimées tous les jours."
"Use the API to collect data","Utiliser l'API pour collecter les données"
"If set to Yes, the tracking script will use the dedicated Rest API endpoint to send its data instead of using the legacy invisible pixel method. Useful if you have issues white-listing the tracker image URL with parameters in your frontend cache or if you customized the data collection and the tracker needs to send bigger payloads than usual.","Si réglé à Oui, le script de tracking utilisera le point d'entrée d'API Rest dédié pour envoyer ses données au lieu d'utiliser la méthode traditionnelle du pixel invisible. Utile si vous avez des soucis pour autoriser l'URL d'image avec des paramètres du tracker dans votre cache front ou bien si vous avez modifié la collecte des données du tracker et que ce dernier doit envoyer beaucoup plus de données."
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
<script>
//<![CDATA[
try {
smileTracker.setConfig({
let trackerConfig = {
beaconUrl : '<?= /* @noEscape */ $this->escapeJsQuote($block->getBeaconUrl()); ?>',
telemetryUrl : '<?= /* @noEscape */ $this->escapeJsQuote($block->getTelemetryUrl()); ?>',
telemetryEnabled : '<?= /* @noEscape */ $this->escapeJsQuote($block->isTelemetryEnabled()); ?>',
sessionConfig : <?= /* @noEscape */ $jsonHelper->jsonEncode($block->getCookieConfig()); ?>,
});
};
<?php if ($block->isUsingAPI()): ?>
trackerConfig.endpointUrl = '<?= /* @noEscape */ $this->escapeJsQuote($block->getEndpointUrl()); ?>';
<?php endif; ?>
smileTracker.setConfig(trackerConfig);

smileTracker.addPageVar('store_id', '<?= /* @noEscape */ $this->escapeJsQuote($block->getStoreId());?>');

Expand Down
Loading

0 comments on commit 464c21f

Please sign in to comment.