Skip to content

Commit

Permalink
Version 2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Jul 22, 2020
1 parent 167dfdb commit 22a4b76
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 51 deletions.
18 changes: 10 additions & 8 deletions Block/Data/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ protected function _prepareLayout()
{
/** @var $tm DataLayer */
$tm = $this->getParentBlock();
$product = $this->getProduct();

if ($product) {
if ($product = $this->getProduct()) {
$productData = [
'id' => $product->getId(),
'sku' => $product->getSku(),
Expand Down Expand Up @@ -99,15 +98,18 @@ public function getPrice()
{
/** @var $tm DataLayer */
$tm = $this->getParentBlock();
$price = 0;

/** @var $product ProductInterface */
$product = $this->getProduct();

if ($product->getTypeId() == Type::TYPE_SIMPLE) {
return $tm->formatPrice($product->getPrice());
} else {
return $tm->formatPrice($product->getFinalPrice());
if ($product = $this->getProduct()) {
if ($product->getTypeId() == Type::TYPE_SIMPLE) {
$price = $product->getPrice();
} else {
$price = $product->getFinalPrice();
}
}

return $tm->formatPrice($price);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Block/DataLayerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

/**
* @method getList()
* @method setListType()
* @method getListType()
*/
class DataLayerAbstract extends Template
{
Expand Down
1 change: 0 additions & 1 deletion Block/GtmCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class GtmCode extends Template
{

/**
* @var GtmHelper
*/
Expand Down
25 changes: 17 additions & 8 deletions Helper/DataLayerItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ public function isCategoryLayerEnabled($store_id = null)
}

/**
* @param OrderItem $item
* @param OrderItem $item | QuoteItem $item
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getCategories($item)
{
if (!$this->isCategoryLayerEnabled()) {
if (!$this->isCategoryLayerEnabled() || !$item->getProduct()) {
return [];
}

Expand Down Expand Up @@ -147,13 +148,17 @@ public function getItemVariant($item)
}

if (!array_key_exists($item->getItemId(), $this->variants)) {
$productOptions = [];

if ($item instanceof OrderItem) {
$productOptions = $this->getItemOptions($item->getProductOptions());
} elseif ($item instanceof QuoteItem) {
$itemOptionInstance = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
} elseif ($item instanceof QuoteItem
&& $item->getProduct()
&& $item->getProduct()->getCustomOption('simple_product')
&& $item->getProduct()->getCustomOption('simple_product')->getProduct()
) {
$itemOptionInstance = $item->getProduct()->getTypeInstance()->getOrderOptions($item->getProduct());
$productOptions = $this->getItemOptions($itemOptionInstance);
} else {
$productOptions = '';
}

$this->variants[$item->getItemId()] = $this->getItemVariantOption($productOptions);
Expand Down Expand Up @@ -211,11 +216,15 @@ public function getProductObject($item, $qty)
$product = [
'name' => $item->getName(),
'id' => $item->getSku(),
'price' => $this->formatPrice($item->getPrice() ?: $item->getProduct()->getPrice()),
'price' => $this->formatPrice($item->getPrice()),
'quantity' => $qty * 1,
'parent_sku' => $item->getProduct()->getData('sku'),
'parent_sku' => $item->getProduct() ? $item->getProduct()->getData('sku') : $item->getSku(),
];

if (!$item->getPrice() && $item->getProduct()) {
$product['price'] = $this->formatPrice($item->getProduct()->getPrice());
}

if ($variant = $this->getItemVariant($item)) {
$product['variant'] = $variant;
}
Expand Down
5 changes: 2 additions & 3 deletions Model/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Item;
use MagePal\GoogleTagManager\DataLayer\QuoteData\QuoteItemProvider;
use MagePal\GoogleTagManager\DataLayer\QuoteData\QuoteProvider;
use MagePal\GoogleTagManager\Helper\DataLayerItem as dataLayerItemHelper;
Expand All @@ -27,7 +26,7 @@ class Cart extends DataObject
protected $checkoutSession;

/**
* @var dataLayerdataLayerItemHelper
* @var dataLayerItemHelper
*/
protected $dataLayerItemHelper;

Expand Down Expand Up @@ -93,7 +92,7 @@ public function getCart()
foreach ($quote->getAllVisibleItems() as $item) {
$itemData = [
'sku' => $item->getSku(),
'parent_sku' => $item->getProduct()->getData('sku'),
'parent_sku' => $item->getProduct() ? $item->getProduct()->getData('sku') : $item->getSku(),
'name' => $this->escapeJsQuote($item->getName()),
'product_type' => $item->getProductType(),
'price' => $this->dataLayerItemHelper->formatPrice($item->getPrice()),
Expand Down
10 changes: 5 additions & 5 deletions Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Order extends DataObject
protected $gtmHelper;

/**
* @var CollectionFactory
* @var CollectionFactoryInterface
*/
protected $_salesOrderCollection;

Expand Down Expand Up @@ -113,7 +113,7 @@ public function getOrderLayer()

$result = [];

/* @var OrderAlias $order */
/* @var SalesOrder $order */

foreach ($collection as $order) {
$products = [];
Expand Down Expand Up @@ -204,20 +204,20 @@ public function escapeReturn($data)
}

/**
* @param OrderAlias $order
* @param SalesOrder $order
* @return array
* @throws NoSuchEntityException
*/
public function getOrderDataLayer(SalesOrder $order)
{
/* @var OrderAlias $order */
/* @var SalesOrder $order */
/* @var Item $item */
$products = [];
foreach ($order->getAllVisibleItems() as $item) {
$product = [
'sku' => $item->getSku(),
'id' => $item->getSku(),
'parent_sku' => $item->getProduct()->getData('sku'),
'parent_sku' => $item->getProduct() ? $item->getProduct()->getData('sku') : $item->getSku(),
'name' => $this->escapeJsQuote($item->getProductOptionByCode('simple_name') ?: $item->getName()),
'parent_name' => $this->escapeJsQuote($item->getName()),
'price' => $this->gtmHelper->formatPrice($item->getBasePrice()),
Expand Down
96 changes: 73 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,33 @@
#### Whether you are a small Magento retailer or an Enterprise customer, our suite of Google Tag Manager extensions will help you integrate the most challenging GTM projects within days, instead of spending weeks or months creating custom solutions.
For Magento 2.0.x, 2.1.x, 2.2.x and 2.3.x

<a href="https://www.magepal.com/magento2/extensions/digital-marketing.html"><img alt="Magento Enhanced Ecommerce for Google Tag Manager" src="https://user-images.githubusercontent.com/1415141/88172990-d89cd300-cbef-11ea-8a51-cc39f55b0218.png" /></a>

### What is Google Tag Manager
Google Tag Manager (GTM) is a user-friendly, powerful and essential integration for every Magento store. It simplifies the process of adding, editing and managing third-party JavaScript tags and other snippets of code on your Magento site.
With GTM, you can quickly and easily add Facebook tags, AdWords Conversion Tracking, Re-marketing, Bing UET, SnapChat, DoubleClick code, Google Analytics and many more in a breeze without the need for a developer to make changes to your Magento code providing the data is available to Google Tag Manager.
Google Tag Manager (GTM) is a user-friendly, powerful and essential integration for every Magento store. It simplifies
the process of adding, editing and managing third-party JavaScript tags and other snippets of code on your Magento site.
With GTM, you can quickly and easily add Facebook tags, AdWords Conversion Tracking, Re-marketing, Bing UET, SnapChat,
DoubleClick code, Google Analytics, and many more in a breeze without the need for a developer to make changes to your
Magento code providing the data is available to Google Tag Manager.

Google Tag Manager makes running your digital marketing campaigns much easier when calibrating with multiple department and Ad agencies by making available the right set of tools so that everyone can get their job done quickly without relying on developers.

Without having the all data you need at your finger tips your integration will become a difficult, time consuming and messy since each developer will only focus on the current task at hand instead of focusing on writing reusable components for future integration.
Without having the all data you need at your finger tips your integration will become a difficult, time-consuming and messy since each developer will only focus on the current task at hand instead of focusing on writing reusable components for future integration.

Our extension provide a vast array of over 60 preconfigure data layer elements to make integrating your Magento store with any other third-party service a breeze using Google Tag Manager.
Our extension provides a vast array of over 60 preconfigure data layer elements to make integrating your Magento store with any other third-party service a breeze using Google Tag Manager.
Extracting, customizing and adding your own custom data from your Magento store to Google Tag Manager is as easy as 10 lines of code using our easy to customize APIs.

>:warning: Google Tag Manager 2.4.0 has some breaking changes to Enhanced Ecommerce. Please download the latest version of Enhanced Ecommerce 1.4.0 or greater from www.magepal.com account.
>:warning: Google Tag Manager 2.5.0 has some breaking changes to Enhanced Ecommerce. Please download the latest version of Enhanced Ecommerce 1.5.0 or greater from www.magepal.com account.

### Why use our Google Tag Manager extension?
Adding Google Tag Manager code snippet to the header section of your Magento store may seem like the ideal and most efficient way to add GTM to your site. But this will not be sufficient and limit your ability to take full advantage of GTM when integrating third-parties tracking codes that require data from your Magento stores, such as product name, price, items added to cart, order items, total, shipping amount or any other data. Our extension provides hundreds of data elements and events to accomplish any integration and provides the building block to make your next integration a success. With a few lines of code, you can quickly extend our extension to accomplish your most challenging integration. Google Tag Manager is only as powerful as the data layer powering it. 
Adding Google Tag Manager code snippet to the header section of your Magento store may seem like the ideal,
and most efficient way to add GTM to your site. But this will not be sufficient and limit your ability to take
full advantage of GTM when integrating third-parties tracking codes that require data from your Magento stores,
such as product name, price, items added to cart, order items, total, shipping amount or any other data. Our extension
provides hundreds of data elements and events to accomplish any integration and provides the building block to make
your next integration a success. With a few lines of code, you can quickly extend our extension to accomplish your
most challenging integration. Google Tag Manager is only as powerful as the data layer powering it. 
Learn more about [customizing Google Tag Manger](https://www.magepal.com/help/docs/google-tag-manager-for-magento/#api).

### Google Analytics Enhanced E-commerce
Expand All @@ -34,11 +45,12 @@ Learn more about our [Google Enhanced Ecommerce](https://www.magepal.com/enhance

### Third Party Integration with Google Tag Manager
Adding Facebook pixel, Bing UAT, SnapChat or any other third-party code snippet to your website but frustrated by
all the hassle and time it take to configure Google Tag Manager? Learn how simple and easy it is to integrate any
all the hassle and time it takes to configure Google Tag Manager? Learn how simple and easy it is to integrate any
tracking code to your Magento store with our new [DataLayer extension](https://www.magepal.com/datalayer-for-google-tag-manager.html?utm_source=data%20layer%20for%20Google%20Tag%20Manager&utm_medium=github).

### General Data Protection Regulation (GDPR) Support
Now you can quickly disable analytic tracking for customer who do not want to by track by enabling Cookie Restriction Mode or base on existing or non-existing cookie.
Now you can quickly disable analytic tracking for customers' who do not want to by track by enabling Cookie Restriction
Mode or base on existing or non-existing cookie.

- Stores > Configuration > General > Web > Default Cookie Settings > Cookie Restriction Mode.

Expand All @@ -49,7 +61,7 @@ Please Note: Merchants should consult with their own legal counsel to ensure tha
| Features | GTM | EE | DL |
|-----------------------------|:---:|:--:|:--:|
| Global Page Tracking | X | X | |
| Order Transaction Tracking | X | X | |
| Order Conversion Tracking | X | X | |
| Page Type Event | | X | |
| Product Clicks | | X | |
| Product Detail Impressions | | X | |
Expand Down Expand Up @@ -80,17 +92,24 @@ DL - [DataLayer for Google Tag Manager Extension](https://www.magepal.com/magent
* Fully customizable with 10 lines of code
* General Data Protection Regulation (GDPR) Support

![Google Tag Manager for Magento](https://image.ibb.co/dhmoLx/Google_Tag_Manager_for_Magento2_by_Magepal.png)

### Benefits of using Google Tag Manager with Magento
There are a number of benefits to using GTM with Magento:

- One Centralized Tag Management source - Google tag Manager is one of the tops and most widely used JavaScript tag management, therefore, anyone with Google Tag Manager experience will have all the knowledge they need to make edits to your site.
- Little to No Technically Knowledge - Digital marketer agencies with so tech skills can quickly make and publish changes to Google Tag Manager without needing to call in developers.
- Version Control - Every change to your Googe Tag Manager container is tracked with a history of who and what was changed.
- Easy to Use - Google Tag Manager is very simple and easy to use. You can easily export your GTM configuration in a text file that could be saved and reimport.
- Reduce Number of Magento Extensions Needed - Installing individual extensions for AdWords, Facebook tracking, Snapchat, Microsoft Bing is time consuming and resource intensive on your Magento store. Using Tag Manager you only need to install and maintaining one extension.
- Eliminate Themes and Order Success Page Edits - 99% of merchants, developers and agencies don't know or use best practice when inserting javascript tracking code snippets to a Magento store, and often just add hardcode each javascript code snippets at random places within the themes files which make it unmaintainable over time as you switch between different service provider.
- One Centralized Tag Management source - Google tag Manager is one of the tops, and most widely used JavaScript tag
management, therefore, anyone with Google Tag Manager experience will have all the knowledge they need to make edits
to your site.
- Little to No Technically Knowledge - Digital marketer agencies with so tech skills can quickly make and publish
changes to Google Tag Manager without needing to call in developers.
- Version Control - Every change to your Google Tag Manager container is track with a history of who and what was changed.
- Easy to Use - Google Tag Manager is very simple and easy to use. You can easily export your GTM configuration in a
text file that could be saved and reimport.
- Reduce Number of Magento Extensions Needed - Installing individual extensions for AdWords, Facebook tracking,
Snapchat, Microsoft Bing is time-consuming and resource intensive on your Magento store. Using Tag Manager you only
need to install and maintaining one extension.
- Eliminate Themes and Order Success Page Edits - 99% of merchants, developers and agencies don't know or use best
practice when inserting javascript tracking code snippets to a Magento store, and often just add hardcode each
javascript code snippets at random places within the themes files which make it unmaintainable over time as you switch
between different service provider.

### How to Customize Google Tag Manager Extension
Need to add more data to your data layer or change existing data to meet your client needs?
Expand Down Expand Up @@ -121,11 +140,42 @@ composer require magepal/magento2-googletagmanager

Our Magento extension provide a vast array of over 60 preconfigure data layer elements to make integrating your Magento store with any third-party service a breeze using Google Tag Manager.

* Trigger: event equals gtm.dom
* pageType (i.e catalog_category_view)
* list (cart, category, detail, other)

### Triggered Events

##### Home Page Events
* Events
* homePage**, allPage**, cmsIndexIndexPage**, mpCustomerSession

##### Category Page Events
* Events
* productImpression*, categoryPage**, allPage**, catalogCategoryViewPage**, mpCustomerSession
* productClick*, addToCart*, productListSwatchClicked**, productListSwatchSelected**

##### Product Detail Page Events
* Events
* productDetail*, productImpression*, productPage**, allPage**, catalogProductViewPage**, mpCustomerSession
* productClick*, addToCart*, removeFromCart*, productDetailSwatchClicked**, productDetailSwatchSelected**, addToCartItemOutOfStock*, addToCartItemOptionRequired*

##### Shopping Cart Page Events
* Events
* cartPage**, allPage**, checkoutCartIndexPage**, productImpression*, mpCustomerSession
* productClick*, addToCart*, removeFromCart*

##### Checkout Page Events
* Events
* checkoutPage**, allPage**, checkoutIndexIndexPage**, checkout*, checkoutOption*, mpCustomerSession
* checkoutEmailValidation*, shippingMethodAdded*, checkoutShippingStepCompleted*, checkoutShippingStepFailed*, paymentMethodAdded*, checkoutPaymentStepFailed*, checkoutPaymentStepCompleted*

##### Order Confirmation Page Events
* Events
* purchase*, orderSuccessPage**, allPage**, checkoutOnepageSuccessPage**

##### Other Events
* Events
* compareProductAdded**, compareProductRemoved**, wishlistProductAdded**, wishlistProductRemoved**, customerLoginAfter**, customerRegisterAfter**, newsletterSubscriberAdded** newsletterUnsubscribed**

### Data Layer Variables

#### Customer
* Trigger: event equals mpCustomerSession
* customer.isLoggedIn
Expand Down Expand Up @@ -304,7 +354,7 @@ Support
---
If you encounter any problems or bugs, please open an issue on [GitHub](https://github.com/magepal/magento2-googletagmanager/issues). For fast Premium Support visit our [Google Tag Manager](https://www.magepal.com/magento2/extensions/google-tag-manager.html?utm_source=GTM&utm_medium=Premium%20Support) product page for detail.

Need help setting up or want to customize this extension to meet your business needs? Please email support@magepal.com and if we like your idea we will add this feature for free or at a discounted rate.
Need help to set up or want to customize our extension to meet your business needs? Please email support@magepal.com and if we like your idea we will add this feature for free or at a discounted rate.

Magento 2 Extensions
---
Expand All @@ -325,4 +375,4 @@ Magento 2 Extensions
- [Custom SMTP](https://www.magepal.com/magento2/extensions/custom-smtp.html)
- [Catalog Hover Image for Magento](https://www.magepal.com/magento2/extensions/catalog-hover-image-for-magento.html)

© MagePal LLC. | [www.magepal.com](http:/www.magepal.com)
© MagePal LLC. | [www.magepal.com](https://www.magepal.com)
Loading

0 comments on commit 22a4b76

Please sign in to comment.