Skip to content

Commit 22a4b76

Browse files
committed
Version 2.5.0
1 parent 167dfdb commit 22a4b76

File tree

8 files changed

+113
-51
lines changed

8 files changed

+113
-51
lines changed

Block/Data/Product.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ protected function _prepareLayout()
6262
{
6363
/** @var $tm DataLayer */
6464
$tm = $this->getParentBlock();
65-
$product = $this->getProduct();
6665

67-
if ($product) {
66+
if ($product = $this->getProduct()) {
6867
$productData = [
6968
'id' => $product->getId(),
7069
'sku' => $product->getSku(),
@@ -99,15 +98,18 @@ public function getPrice()
9998
{
10099
/** @var $tm DataLayer */
101100
$tm = $this->getParentBlock();
101+
$price = 0;
102102

103103
/** @var $product ProductInterface */
104-
$product = $this->getProduct();
105-
106-
if ($product->getTypeId() == Type::TYPE_SIMPLE) {
107-
return $tm->formatPrice($product->getPrice());
108-
} else {
109-
return $tm->formatPrice($product->getFinalPrice());
104+
if ($product = $this->getProduct()) {
105+
if ($product->getTypeId() == Type::TYPE_SIMPLE) {
106+
$price = $product->getPrice();
107+
} else {
108+
$price = $product->getFinalPrice();
109+
}
110110
}
111+
112+
return $tm->formatPrice($price);
111113
}
112114

113115
/**

Block/DataLayerAbstract.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* @method getList()
18+
* @method setListType()
19+
* @method getListType()
1820
*/
1921
class DataLayerAbstract extends Template
2022
{

Block/GtmCode.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
class GtmCode extends Template
1515
{
16-
1716
/**
1817
* @var GtmHelper
1918
*/

Helper/DataLayerItem.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ public function isCategoryLayerEnabled($store_id = null)
6969
}
7070

7171
/**
72-
* @param OrderItem $item
72+
* @param OrderItem $item | QuoteItem $item
7373
* @return array
74+
* @throws \Magento\Framework\Exception\LocalizedException
7475
*/
7576
public function getCategories($item)
7677
{
77-
if (!$this->isCategoryLayerEnabled()) {
78+
if (!$this->isCategoryLayerEnabled() || !$item->getProduct()) {
7879
return [];
7980
}
8081

@@ -147,13 +148,17 @@ public function getItemVariant($item)
147148
}
148149

149150
if (!array_key_exists($item->getItemId(), $this->variants)) {
150-
$productOptions = [];
151-
152151
if ($item instanceof OrderItem) {
153152
$productOptions = $this->getItemOptions($item->getProductOptions());
154-
} elseif ($item instanceof QuoteItem) {
155-
$itemOptionInstance = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
153+
} elseif ($item instanceof QuoteItem
154+
&& $item->getProduct()
155+
&& $item->getProduct()->getCustomOption('simple_product')
156+
&& $item->getProduct()->getCustomOption('simple_product')->getProduct()
157+
) {
158+
$itemOptionInstance = $item->getProduct()->getTypeInstance()->getOrderOptions($item->getProduct());
156159
$productOptions = $this->getItemOptions($itemOptionInstance);
160+
} else {
161+
$productOptions = '';
157162
}
158163

159164
$this->variants[$item->getItemId()] = $this->getItemVariantOption($productOptions);
@@ -211,11 +216,15 @@ public function getProductObject($item, $qty)
211216
$product = [
212217
'name' => $item->getName(),
213218
'id' => $item->getSku(),
214-
'price' => $this->formatPrice($item->getPrice() ?: $item->getProduct()->getPrice()),
219+
'price' => $this->formatPrice($item->getPrice()),
215220
'quantity' => $qty * 1,
216-
'parent_sku' => $item->getProduct()->getData('sku'),
221+
'parent_sku' => $item->getProduct() ? $item->getProduct()->getData('sku') : $item->getSku(),
217222
];
218223

224+
if (!$item->getPrice() && $item->getProduct()) {
225+
$product['price'] = $this->formatPrice($item->getProduct()->getPrice());
226+
}
227+
219228
if ($variant = $this->getItemVariant($item)) {
220229
$product['variant'] = $variant;
221230
}

Model/Cart.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Framework\Exception\LocalizedException;
1414
use Magento\Framework\Exception\NoSuchEntityException;
1515
use Magento\Quote\Model\Quote;
16-
use Magento\Quote\Model\Quote\Item;
1716
use MagePal\GoogleTagManager\DataLayer\QuoteData\QuoteItemProvider;
1817
use MagePal\GoogleTagManager\DataLayer\QuoteData\QuoteProvider;
1918
use MagePal\GoogleTagManager\Helper\DataLayerItem as dataLayerItemHelper;
@@ -27,7 +26,7 @@ class Cart extends DataObject
2726
protected $checkoutSession;
2827

2928
/**
30-
* @var dataLayerdataLayerItemHelper
29+
* @var dataLayerItemHelper
3130
*/
3231
protected $dataLayerItemHelper;
3332

@@ -93,7 +92,7 @@ public function getCart()
9392
foreach ($quote->getAllVisibleItems() as $item) {
9493
$itemData = [
9594
'sku' => $item->getSku(),
96-
'parent_sku' => $item->getProduct()->getData('sku'),
95+
'parent_sku' => $item->getProduct() ? $item->getProduct()->getData('sku') : $item->getSku(),
9796
'name' => $this->escapeJsQuote($item->getName()),
9897
'product_type' => $item->getProductType(),
9998
'price' => $this->dataLayerItemHelper->formatPrice($item->getPrice()),

Model/Order.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Order extends DataObject
3535
protected $gtmHelper;
3636

3737
/**
38-
* @var CollectionFactory
38+
* @var CollectionFactoryInterface
3939
*/
4040
protected $_salesOrderCollection;
4141

@@ -113,7 +113,7 @@ public function getOrderLayer()
113113

114114
$result = [];
115115

116-
/* @var OrderAlias $order */
116+
/* @var SalesOrder $order */
117117

118118
foreach ($collection as $order) {
119119
$products = [];
@@ -204,20 +204,20 @@ public function escapeReturn($data)
204204
}
205205

206206
/**
207-
* @param OrderAlias $order
207+
* @param SalesOrder $order
208208
* @return array
209209
* @throws NoSuchEntityException
210210
*/
211211
public function getOrderDataLayer(SalesOrder $order)
212212
{
213-
/* @var OrderAlias $order */
213+
/* @var SalesOrder $order */
214214
/* @var Item $item */
215215
$products = [];
216216
foreach ($order->getAllVisibleItems() as $item) {
217217
$product = [
218218
'sku' => $item->getSku(),
219219
'id' => $item->getSku(),
220-
'parent_sku' => $item->getProduct()->getData('sku'),
220+
'parent_sku' => $item->getProduct() ? $item->getProduct()->getData('sku') : $item->getSku(),
221221
'name' => $this->escapeJsQuote($item->getProductOptionByCode('simple_name') ?: $item->getName()),
222222
'parent_name' => $this->escapeJsQuote($item->getName()),
223223
'price' => $this->gtmHelper->formatPrice($item->getBasePrice()),

README.md

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,33 @@
88
#### 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.
99
For Magento 2.0.x, 2.1.x, 2.2.x and 2.3.x
1010

11+
<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>
12+
1113
### What is Google Tag Manager
12-
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.
13-
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.
14+
Google Tag Manager (GTM) is a user-friendly, powerful and essential integration for every Magento store. It simplifies
15+
the process of adding, editing and managing third-party JavaScript tags and other snippets of code on your Magento site.
16+
With GTM, you can quickly and easily add Facebook tags, AdWords Conversion Tracking, Re-marketing, Bing UET, SnapChat,
17+
DoubleClick code, Google Analytics, and many more in a breeze without the need for a developer to make changes to your
18+
Magento code providing the data is available to Google Tag Manager.
1419

1520
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.
1621

17-
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.
22+
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.
1823

19-
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.
24+
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.
2025
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.
2126

22-
>: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.
27+
>: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.
2328
2429

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

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

3546
### Third Party Integration with Google Tag Manager
3647
Adding Facebook pixel, Bing UAT, SnapChat or any other third-party code snippet to your website but frustrated by
37-
all the hassle and time it take to configure Google Tag Manager? Learn how simple and easy it is to integrate any
48+
all the hassle and time it takes to configure Google Tag Manager? Learn how simple and easy it is to integrate any
3849
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).
3950

4051
### General Data Protection Regulation (GDPR) Support
41-
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.
52+
Now you can quickly disable analytic tracking for customers' who do not want to by track by enabling Cookie Restriction
53+
Mode or base on existing or non-existing cookie.
4254

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

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

83-
![Google Tag Manager for Magento](https://image.ibb.co/dhmoLx/Google_Tag_Manager_for_Magento2_by_Magepal.png)
84-
8595
### Benefits of using Google Tag Manager with Magento
8696
There are a number of benefits to using GTM with Magento:
8797

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

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

122141
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.
123142

124-
* Trigger: event equals gtm.dom
125-
* pageType (i.e catalog_category_view)
126-
* list (cart, category, detail, other)
127-
143+
### Triggered Events
128144

145+
##### Home Page Events
146+
* Events
147+
* homePage**, allPage**, cmsIndexIndexPage**, mpCustomerSession
148+
149+
##### Category Page Events
150+
* Events
151+
* productImpression*, categoryPage**, allPage**, catalogCategoryViewPage**, mpCustomerSession
152+
* productClick*, addToCart*, productListSwatchClicked**, productListSwatchSelected**
153+
154+
##### Product Detail Page Events
155+
* Events
156+
* productDetail*, productImpression*, productPage**, allPage**, catalogProductViewPage**, mpCustomerSession
157+
* productClick*, addToCart*, removeFromCart*, productDetailSwatchClicked**, productDetailSwatchSelected**, addToCartItemOutOfStock*, addToCartItemOptionRequired*
158+
159+
##### Shopping Cart Page Events
160+
* Events
161+
* cartPage**, allPage**, checkoutCartIndexPage**, productImpression*, mpCustomerSession
162+
* productClick*, addToCart*, removeFromCart*
163+
164+
##### Checkout Page Events
165+
* Events
166+
* checkoutPage**, allPage**, checkoutIndexIndexPage**, checkout*, checkoutOption*, mpCustomerSession
167+
* checkoutEmailValidation*, shippingMethodAdded*, checkoutShippingStepCompleted*, checkoutShippingStepFailed*, paymentMethodAdded*, checkoutPaymentStepFailed*, checkoutPaymentStepCompleted*
168+
169+
##### Order Confirmation Page Events
170+
* Events
171+
* purchase*, orderSuccessPage**, allPage**, checkoutOnepageSuccessPage**
172+
173+
##### Other Events
174+
* Events
175+
* compareProductAdded**, compareProductRemoved**, wishlistProductAdded**, wishlistProductRemoved**, customerLoginAfter**, customerRegisterAfter**, newsletterSubscriberAdded** newsletterUnsubscribed**
176+
177+
### Data Layer Variables
178+
129179
#### Customer
130180
* Trigger: event equals mpCustomerSession
131181
* customer.isLoggedIn
@@ -304,7 +354,7 @@ Support
304354
---
305355
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.
306356

307-
Need help setting up or want to customize this extension to meet your business needs? Please email [email protected] and if we like your idea we will add this feature for free or at a discounted rate.
357+
Need help to set up or want to customize our extension to meet your business needs? Please email [email protected] and if we like your idea we will add this feature for free or at a discounted rate.
308358

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

328-
© MagePal LLC. | [www.magepal.com](http:/www.magepal.com)
378+
© MagePal LLC. | [www.magepal.com](https://www.magepal.com)

0 commit comments

Comments
 (0)