Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
ddba8c77
Commit
ddba8c77
authored
Feb 28, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : 添加google gtm 事件
parent
8535f2b8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
4 deletions
+86
-4
app/code/Magento/Checkout/view/frontend/templates/cart/form.phtml
+28
-3
app/design/frontend/Joshine/breeze/Magento_Catalog/templates/product/list.phtml
+20
-0
app/design/frontend/Joshine/breeze/Magento_Catalog/templates/product/view/details.phtml
+14
-0
app/design/frontend/Joshine/breeze/Magento_Checkout/templates/success.phtml
+24
-1
No files found.
app/code/Magento/Checkout/view/frontend/templates/cart/form.phtml
View file @
ddba8c77
...
@@ -7,6 +7,22 @@
...
@@ -7,6 +7,22 @@
// phpcs:disable Magento2.Templates.ThisInTemplate
// phpcs:disable Magento2.Templates.ThisInTemplate
/** @var $block \Magento\Checkout\Block\Cart\Grid */
/** @var $block \Magento\Checkout\Block\Cart\Grid */
$objectManager
=
\Magento\Framework\App\ObjectManager
::
getInstance
();
$_cart
=
$objectManager
->
get
(
'\Magento\Checkout\Model\Cart'
);
$items
=
[];
$priceSum
=
0
;
$_items
=
$_cart
->
getQuote
()
->
getAllItems
();
if
(
count
(
$_items
)
>
0
)
{
foreach
(
$_items
as
$key
=>
$value
)
{
$_item
[
'google_business_vertical'
]
=
'retail'
;
$_item
[
'id'
]
=
$value
->
getSku
();
$items
[]
=
$_item
;
$priceSum
+=
$value
->
getPrice
();
}
}
?>
?>
<?php
$mergedCells
=
(
$this
->
helper
(
Magento\Tax\Helper\Data
::
class
)
->
displayCartBothPrices
()
?
2
:
1
);
?>
<?php
$mergedCells
=
(
$this
->
helper
(
Magento\Tax\Helper\Data
::
class
)
->
displayCartBothPrices
()
?
2
:
1
);
?>
<?=
$block
->
getChildHtml
(
'form_before'
)
?>
<?=
$block
->
getChildHtml
(
'form_before'
)
?>
...
@@ -32,9 +48,9 @@
...
@@ -32,9 +48,9 @@
<caption
class=
"table-caption"
>
<?=
$block
->
escapeHtml
(
__
(
'Shopping Cart Items'
))
?>
</caption>
<caption
class=
"table-caption"
>
<?=
$block
->
escapeHtml
(
__
(
'Shopping Cart Items'
))
?>
</caption>
<thead>
<thead>
<tr>
<tr>
<th
class=
"col item"
scope=
"col"
><span>
<?=
$block
->
escapeHtml
(
__
(
'Item'
))
?>
</span></th>
<th
class=
"col item"
scope=
"col"
><span>
<?=
$block
->
escapeHtml
(
__
(
'Item'
))
?>
</span></th>
<th
class=
"col price"
scope=
"col"
><span>
<?=
$block
->
escapeHtml
(
__
(
'Price'
))
?>
</span></th>
<th
class=
"col price"
scope=
"col"
><span>
<?=
$block
->
escapeHtml
(
__
(
'Price'
))
?>
</span></th>
<th
class=
"col qty"
scope=
"col"
><span>
<?=
$block
->
escapeHtml
(
__
(
'Qty'
))
?>
</span></th>
<th
class=
"col qty"
scope=
"col"
><span>
<?=
$block
->
escapeHtml
(
__
(
'Qty'
))
?>
</span></th>
<th
class=
"col subtotal"
scope=
"col"
><span>
<?=
$block
->
escapeHtml
(
__
(
'Subtotal'
))
?>
</span></th>
<th
class=
"col subtotal"
scope=
"col"
><span>
<?=
$block
->
escapeHtml
(
__
(
'Subtotal'
))
?>
</span></th>
</tr>
</tr>
</thead>
</thead>
...
@@ -106,5 +122,14 @@ require(['jquery'], function ($) {
...
@@ -106,5 +122,14 @@ require(['jquery'], function ($) {
});
});
});
});
</script>
</script>
<script>
dataLayer
=
[];
dataLayer
=
[];
dataLayer
.
push
({
'event'
:
'add_to_cart'
,
'value'
:
<?=
$priceSum
?>
,
'items'
:
<?=
json_encode
(
$items
,
true
)
?>
);
</script>
<?=
$block
->
getChildHtml
(
'checkout.cart.order.actions'
)
?>
<?=
$block
->
getChildHtml
(
'checkout.cart.order.actions'
)
?>
<?=
$block
->
getChildHtml
(
'shopping.cart.table.after'
)
?>
<?=
$block
->
getChildHtml
(
'shopping.cart.table.after'
)
?>
app/design/frontend/Joshine/breeze/Magento_Catalog/templates/product/list.phtml
View file @
ddba8c77
...
@@ -43,6 +43,18 @@ $_helper = $block->getData('outputHelper');
...
@@ -43,6 +43,18 @@ $_helper = $block->getData('outputHelper');
* Position for actions regarding image size changing in vde if needed
* Position for actions regarding image size changing in vde if needed
*/
*/
$pos
=
$block
->
getPositioned
();
$pos
=
$block
->
getPositioned
();
$price
=
0
;
$items
=
[];
if
(
$_productCollection
->
getSize
()
>
0
)
{
$price
=
array_sum
(
$_productCollection
->
getColumnValues
(
'price'
));
foreach
(
$_productCollection
as
$key
=>
$product
)
{
$_product
[
'id'
]
=
$product
->
getSku
();
$_product
[
'google_business_vertical'
]
=
'retail'
;
$items
[]
=
$_product
;
}
}
$googleGtmName
=
is_null
(
$pos
)
?
'view_item_list'
:
'view_search_results'
;
?>
?>
<style>
<style>
.mode-list
{
.mode-list
{
...
@@ -199,4 +211,12 @@ $_helper = $block->getData('outputHelper');
...
@@ -199,4 +211,12 @@ $_helper = $block->getData('outputHelper');
}
}
}
}
</script>
</script>
<script>
dataLayer
=
[];
dataLayer
.
push
({
'event'
:
<?=
$googleGtmName
?>
,
'value'
:
<?=
$price
?>
,
'item'
:
<?=
json_encode
(
$items
,
true
)
?>
})
</script>
<?php
endif
;
?>
<?php
endif
;
?>
app/design/frontend/Joshine/breeze/Magento_Catalog/templates/product/view/details.phtml
View file @
ddba8c77
...
@@ -3,6 +3,9 @@
...
@@ -3,6 +3,9 @@
* Copyright © Magento, Inc. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* See COPYING.txt for license details.
*/
*/
$objectManager
=
\Magento\Framework\App\ObjectManager
::
getInstance
();
$product
=
$objectManager
->
get
(
'Magento\Framework\Registry'
)
->
registry
(
'current_product'
);
/** @var \Magento\Catalog\Block\Product\View\Details $block */
/** @var \Magento\Catalog\Block\Product\View\Details $block */
?>
?>
...
@@ -48,5 +51,16 @@
...
@@ -48,5 +51,16 @@
$
(
"#tab-label-reviews"
).
trigger
(
"click"
);
$
(
"#tab-label-reviews"
).
trigger
(
"click"
);
},
8000
);
},
8000
);
});
});
window
.
dataLayer
=
window
.
dataLayer
||
[];
dataLayer
.
push
({
'event'
:
'view_item'
,
'value'
:
'
<?=
$product
->
getFinalPrice
()
?>
'
,
'items'
:
[{
'id'
:
<?=
$product
->
getSku
()
?>
,
'google_business_vertical'
:
'retail'
}]
});
</script>
</script>
app/design/frontend/Joshine/breeze/Magento_Checkout/templates/success.phtml
View file @
ddba8c77
...
@@ -3,7 +3,22 @@
...
@@ -3,7 +3,22 @@
* Copyright © Magento, Inc. All rights reserved.
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* See COPYING.txt for license details.
*/
*/
$lid
=
$this
->
getOrderId
();
$total
=
0
;
$items
=
[];
if
(
$lid
)
{
$objectManager
=
\Magento\Framework\App\ObjectManager
::
getInstance
();
$order
=
$objectManager
->
create
(
'Magento\Sales\Model\Order'
)
->
load
(
$lid
);
if
(
$order
)
{
$total
=
$order
->
getGrandTotal
();
$_items
=
$order
->
getAllItems
();
foreach
(
$_items
as
$item
)
{
$_item
[
'google_business_vertical'
]
=
'retail'
;
$_item
[
'id'
]
=
$item
->
getSku
();
$items
[]
=
$_item
;
}
}
}
?>
?>
<?php
/** @var $block \Magento\Checkout\Block\Onepage\Success */
?>
<?php
/** @var $block \Magento\Checkout\Block\Onepage\Success */
?>
<div
class=
"checkout-success"
>
<div
class=
"checkout-success"
>
...
@@ -48,3 +63,11 @@
...
@@ -48,3 +63,11 @@
</style>
</style>
<script>
dataLayer
=
[];
dataLayer
.
push
({
'event'
:
'purchase'
,
'value'
:
<?=
$total
?>
,
'items'
:
<?=
json_encode
(
$items
,
true
)
?>
);
</script>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment