Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Block/AbstractPixel.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ protected function _toHtml(): string
fbq("' . $this->getTrackMethod() . '", '
. $this->json->serialize($eventName) . ', '
. $this->json->serialize($parameters) . ', '
. '{ "eventID": "' . $eventName . '" + "." + Math.floor(Math.random() * 1000000) + "." + Date.now(), "event_source_url": window.location.href, "referrer_url": document.referrer }'
. '{ "eventID": "' . $eventName
. '" + "." + Math.floor(Math.random() * 1000000) + "."'
. ' + Date.now(), "event_source_url": window.location.href, "referrer_url": document.referrer }'
. ');
';

Expand All @@ -95,6 +97,8 @@ protected function _toHtml(): string
}

/**
* Get track method
*
* @return string
*/
protected function getTrackMethod(): string
Expand Down
6 changes: 6 additions & 0 deletions Block/Adminhtml/System/Config/Form/InfoConversionApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class InfoConversionApi extends InfoPlan
{

/**
* Get min plan name
*
* @return string
*/
protected function getMinPlan(): string
Expand All @@ -20,6 +22,8 @@ protected function getMinPlan(): string
}

/**
* Get section id
*
* @return string
*/
protected function getSectionId(): string
Expand All @@ -28,6 +32,8 @@ protected function getSectionId(): string
}

/**
* Get section text
*
* @return string
*/
protected function getText(): string
Expand Down
18 changes: 15 additions & 3 deletions Block/Adminhtml/System/Config/Form/InfoPlan.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@
abstract class InfoPlan extends \Magefan\Community\Block\Adminhtml\System\Config\Form\Info
{
/**
* Get min plan name
*
* @return string
*/
abstract protected function getMinPlan(): string;

/**
* Get section id
*
* @return string
*/
abstract protected function getSectionId(): string;

/**
* Get section text
*
* @return string
*/
abstract protected function getText(): string;


/**
* Return info block html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
Expand All @@ -39,7 +45,11 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele

$html = '';
$html .= '<div style="padding:10px;background-color:#f8f8f8;border:1px solid #ddd;margin-bottom:7px;">';
$html .= $this->getText() . ' <a style="color: #ef672f; text-decoration: underline;" href="https://magefan.com/magento-2-google-tag-manager/pricing?utm_source=gtm_config&utm_medium=link&utm_campaign=regular" target="_blank">Read more</a>.';
$html .= $this->getText();
$html .= ' <a style="color: #ef672f; text-decoration: underline;" '
. 'href="https://magefan.com/magento-2-google-tag-manager/pricing?utm_source=gtm_config'
. '&utm_medium=link&utm_campaign=regular" target="_blank">'
. 'Read more</a>.';
$html .= '</div>';

$script = '
Expand All @@ -66,7 +76,9 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele
text: "Upgrade Plan Now",
class: "action primary accept",
click: function () {
window.open("https://magefan.com/magento-2-google-tag-manager/pricing?utm_source=gtm_config&utm_medium=link&utm_campaign=regular");
var url = "https://magefan.com/magento-2-google-tag-manager/pricing?"
+ "utm_source=gtm_config&utm_medium=link&utm_campaign=regular";
window.open(url);
}
}]
});
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/System/Config/Form/ProtectCustomerData.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function render(AbstractElement $element): string
{
$url = $this->getUrl('*/*/*/section/web');
$comment = 'When enabled, data won\'t be sent to Facebook, until the customer provides consent.'; /* <br/><br/>
<strong>Note</strong>, that this option will work only when Cookie Restriction Mode at
<strong>Note</strong>, that this option will work only when Cookie Restriction Mode at
<a href="' . $url . '" target="_blank">Stores > Configuration > General > Web > Default Cookie Settings</a>
is enabled.'; */

Expand Down
2 changes: 2 additions & 0 deletions Block/Pixel/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ protected function getEventName(): string
}

/**
* Get current order
*
* @return \Magento\Sales\Model\Order
*/
protected function getOrder()
Expand Down
8 changes: 7 additions & 1 deletion Block/Pixel/PurchaseGetOrderFromRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
class PurchaseGetOrderFromRequest extends Purchase
{
/**
* Get order
*
* @return \Magento\Sales\Model\Order|null
*/
protected function getOrder()
Expand All @@ -24,6 +26,8 @@ protected function getOrder()
}

/**
* Get order factory
*
* @return mixed
*/
protected function getOrderFactory()
Expand All @@ -33,6 +37,8 @@ protected function getOrderFactory()
}

/**
* Get order id
*
* @return string
*/
protected function getOrderId()
Expand All @@ -45,4 +51,4 @@ protected function getOrderId()

return 0;
}
}
}
1 change: 1 addition & 0 deletions Block/Pixel/ViewProductContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private function getCurrentProduct(): Product
if ($productId = $this->_request->getParam('mfpreselect')) {
try {
$product = $this->productRepository->getById($productId);
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
} catch (NoSuchEntityException $e) {

}
Expand Down
2 changes: 2 additions & 0 deletions Model/AbstractPixel.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class AbstractPixel
* @param Config $config
* @param StoreManagerInterface $storeManager
* @param CategoryRepositoryInterface $categoryRepository
* @param RequestInterface|null $request
* @param Registry|null $registry
*/
public function __construct(
Config $config,
Expand Down
12 changes: 6 additions & 6 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public function getProductAttribute(?string $storeId = null): string
return trim((string)$this->getConfig(self::XML_PATH_ATTRIBUTES_PRODUCT, $storeId));
}

/*
* Retrieve Magento product categories
*
* @param string|null $storeId
* @return string
*/
/**
* Retrieve Magento category attribute
*
* @param string|null $storeId
* @return string
*/
public function getCategoriesAttribute(?string $storeId = null): string
{
return trim((string)$this->getConfig(self::XML_PATH_ATTRIBUTES_CATEGORIES, $storeId));
Expand Down
9 changes: 7 additions & 2 deletions Model/Pixel/Cart/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ public function get(Item $quoteItem): array
}

/**
* @param $quoteItem
* Get product from quote item
*
* @param Item $quoteItem
* @return \Magento\Catalog\Api\Data\ProductInterface
*/
protected function getItemProduct($quoteItem)
protected function getItemProduct(Item $quoteItem)
{
$product = $quoteItem->getProduct();
if ('configurable' === $product->getTypeId()) {
Expand All @@ -54,6 +56,7 @@ protected function getItemProduct($quoteItem)
try {
$product = $this->getProductRepository()->getById($option->getProductId());
break;
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
} catch (NoSuchEntityException $e) {

}
Expand All @@ -65,6 +68,8 @@ protected function getItemProduct($quoteItem)
}

/**
* Get product repository instance
*
* @return ProductRepositoryInterface
*/
protected function getProductRepository(): ProductRepositoryInterface
Expand Down
6 changes: 4 additions & 2 deletions Model/Pixel/Order/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ public function get(OrderItemInterface $orderItem): array
}

/**
* @param $orderItem
* Get product from order item
*
* @param OrderItemInterface $orderItem
* @return \Magento\Catalog\Api\Data\ProductInterface
*/
protected function getItemProduct($orderItem)
protected function getItemProduct(OrderItemInterface $orderItem)
{
$product = $orderItem->getProduct();
if ('configurable' === $product->getTypeId()) {
Expand Down
6 changes: 4 additions & 2 deletions Model/Pixel/Purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ public function get(Order $order): array
}

/**
* @param $entity
* Set mf_children_item for each item
*
* @param Order $entity
* @return void
*/
protected function setMfChildrenItem($entity)
protected function setMfChildrenItem(Order $entity)
{
// Use getItem, not getAllItems, to prevent some errors with the custom plugins
foreach ($entity->getItems() as $childrenItem) {
Expand Down
14 changes: 11 additions & 3 deletions view/adminhtml/templates/system/config/event/list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ $eventsExtra = [
</ul>
<p <?php if (!$block->isPlusEnabled()) { ?>style="color: #eb5202"<?php } ?>>
<strong>
<?= $escaper->escapeHtml(__(!$block->isPlusEnabled() ? 'Available in FB Pixel Plus Only' : 'FB Pixel Plus')) ?>
<?= $escaper->escapeHtml(__(!$block->isPlusEnabled()
? 'Available in FB Pixel Plus Only'
: 'FB Pixel Plus')) ?>
<?php if (!$block->isPlusEnabled()) { ?>
(<a style="color: #eb5202; text-decoration: underline;" href="https://magefan.com/magento-2-facebook-pixel/pricing" target="_blank">Read more</a>):
(<a style="color: #eb5202; text-decoration: underline;"
href="https://magefan.com/magento-2-facebook-pixel/pricing" target="_blank">
Read more
</a>):
<?php } ?>
</strong>
</p>
Expand All @@ -60,7 +65,10 @@ $eventsExtra = [
__(!$block->isExtraEnabled() ? 'Available in FB Pixel Extra Only' : 'FB Pixel Extra')
) ?>
<?php if (!$block->isExtraEnabled()) { ?>
(<a style="color: #eb5202; text-decoration: underline;" href="https://magefan.com/magento-2-facebook-pixel/pricing" target="_blank">Read more</a>):
(<a style="color: #eb5202; text-decoration: underline;"
href="https://magefan.com/magento-2-facebook-pixel/pricing" target="_blank">
Read more
</a>):
<?php } ?>
</strong>
</p>
Expand Down
40 changes: 23 additions & 17 deletions view/frontend/templates/pixel.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@ $script = '';
n.queue=[];
f.mfFbq = 1;

let customerData = localStorage.getItem('mage-cache-storage') ? JSON.parse(localStorage.getItem('mage-cache-storage')).customer : false;
let advancedMatching = (customerData && customerData.mf_fb_pixel_customer_data) ? customerData.mf_fb_pixel_customer_data : {};
let customerData = localStorage.getItem('mage-cache-storage')
? JSON.parse(localStorage.getItem('mage-cache-storage')).customer
: false;
let advancedMatching = (customerData && customerData.mf_fb_pixel_customer_data)
? customerData.mf_fb_pixel_customer_data : {};

fbq('init', '{$escaper->escapeHtml($block->getFbPixelId())}', advancedMatching);
fbq('track', 'PageView', {}, {'eventID': 'PageView' + '.' + Math.floor(Math.random() * 1000000) + '.' + Date.now(), 'currency': '" . $block->getCurrentCurrencyCode() . "','event_source_url': window.location.href, 'referrer_url': document.referrer});
fbq('track', 'PageView', {},
{'eventID': 'PageView' + '.' + Math.floor(Math.random() * 1000000) + '.' + Date.now(),
'currency': '" . $block->getCurrentCurrencyCode() . "',
'event_source_url': window.location.href, 'referrer_url': document.referrer});
var triedToLoadPixel = false;
";


if ($block->isSpeedOptimizationEnabled() && $block->getRequest()->getModuleName() !== 'checkout') {
$script .= "
if ($block->isSpeedOptimizationEnabled() && $block->getRequest()->getModuleName() !== 'checkout') {
$script .= "
var actionDetected = false;
document.addEventListener('scroll', initMfFbPixel);
document.addEventListener('mousemove', initMfFbPixel);
Expand All @@ -55,11 +61,11 @@ $script = '';
}
};
";
} else {
$script .= "
} else {
$script .= "
var actionDetected = true;
";
}
}

$script .= "
function mfLoadFbPixel() {
Expand All @@ -75,13 +81,13 @@ $script = '';
";


if ($block->isProtectCustomerDataEnabled()) {
echo $block->getLayout()->createBlock(\Magefan\Community\Block\JsScript::class)
->setMethod('isCustomerConsentProvided')
->setScriptAttributes(['data-rocketjavascript' => 'false'])
->toHtml();
if ($block->isProtectCustomerDataEnabled()) {
echo $block->getLayout()->createBlock(\Magefan\Community\Block\JsScript::class)
->setMethod('isCustomerConsentProvided')
->setScriptAttributes(['data-rocketjavascript' => 'false'])
->toHtml();

$script .= "
$script .= "
document.addEventListener('DOMContentLoaded', function () {
if (MagefanJs.isCustomerConsentProvided()) {
mfLoadFbPixel();
Expand All @@ -94,11 +100,11 @@ $script = '';
}
});
";
} else {
$script .= "
} else {
$script .= "
mfLoadFbPixel();
";
}
}

$script .= "
}(window);
Expand Down