Jump to content

Google Analytics 4 install


sylwekb

Recommended Posts

Hi

In which Prestashop 1.7 files should the following code be added for Google Analytics 4 to work. Has anyone managed to implement it?

To which specific Prestashop files in the code should I put it? What code should make it work dynamically?

1. add_payment_info
Payment method addition / selection event. Below is the script along with
bold comments necessary for implementation, please note that the data
were dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "add_payment_info", // Name of the event
ecommerce: {
currency: "PLN", // Currency
value: 44.00, // Total cart / order value
payment_type: "PayU", // Selected payment method
(optional)
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
2. add_shipping_info
Delivery method addition / selection event. Below is the script along with
bold comments necessary for implementation, please note that the data
were dynamically substituted:
JavaScript
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "add_shipping_info", // Name of the event
ecommerce: {
currency: "PLN", // Currency
value: 44.00, // Total cart / order value
shipping_tier: "INPOST courier", // Chosen method
delivery (optional)
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
3. add_to_cart
Product added to cart event. Below is the script along with
bold comments necessary for implementation, please note that the data
were dynamically substituted:
JavaScript
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "add_to_cart", // Name of the event
ecommerce: {
currency: "PLN", // Currency
value: 44.00, // Total value of added products
to shopping cart
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
4. begin_checkout
The order process start event. Below is the script
along with bold comments necessary for implementation, please note that
for the data to be dynamically substituted:
JavaScript
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "begin_checkout", // Event name
ecommerce: {
currency: "PLN", // Currency
value: 44.00, // Total cart / order value
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
5. purchase
Purchase/order event. Below is the script along with
bold comments necessary for implementation, please note that the data
were dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "purchase", // Event name
ecommerce: {
transaction_id: "12", // Transaction ID
value: 81.00, // Total basket value /
orders
tax: 15.15, // Total value of VAT
shipping: 15.00, // Total shipping cost
currency: "PLN", // Currency
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
},
{
item_id: "54321", // Product ID
item_name: "Soccer superfly", // Name
product
item_brand: "Adidas", // Product brand (optional)
item_category: "Footballs", // Product category
item_variant: "White", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 1 // Amount of products in the cart
}]
}
});
</script>
6. refund
The event of making a return / canceling an order. Below is located
script along with bold comments necessary for implementation, please
remember that the data should be dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "refund", // Event name
ecommerce: {
transaction_id: "12345", // ID
transactions
value: 81.00, // Total basket value /
orders
tax: 15.15, // Total value of VAT
shipping: 15.00, // Total shipping cost
currency: "PLN", // Currency
items: [
{
item_id: "54321", // Product ID
item_name: "Soccer superfly", // Name
product
item_brand: "Adidas", // Product brand (optional)
item_category: "Footballs", // Product category
item_variant: "White", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 1 // Amount of products in the cart
}
]
}
});
</script>

 

7. remove_from_cart
Product removed from cart event. Below is the script along with
bold comments necessary for implementation, please note that the data
were dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "remove_from_cart", // Event name
ecommerce: {
currency: "PLN", // Currency
value: 44.00, // Total value of removed products
from the basket
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
8. select_item
Product listing click/select event. Below is a
script along with bold comments necessary for implementation, please
remember that the data should be dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "select_item", // Name of the event
ecommerce: {
item_list_id: "12345", // List ID
products
item_list_name: "CATEGORY OF THE WEEK", // Name of the list
products
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
9. select_promotion
Promotional banner click/selection event from homepage. Below
there is a script with bold comments necessary for implementation,
remember that the data should be dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "select_promotion", // Event name
ecommerce: {
creative_name: "Summer Banner", // Banner name
promotion_id: "12345", // Promotion ID
promotion_name: "Summer Sale", // Promotion name
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
10. view_cart
Shopping cart display event. Below is the script along with the bolded ones
comments necessary for implementation, remember that the data should be
dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "view_cart", // Event name
ecommerce: {
currency: "PLN", // Currency
value: 44.00, // Total cart / order value
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
11. view_item
The event of displaying a product card or simply a product. Below is a
script along with bold comments necessary for implementation, please
remember that the data should be dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "view_item", // Name of the event
ecommerce: {
currency: "PLN", // Currency
value: 44.00, // Total product value
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
12. view_item_list
Category display or product listing event. Below is the script
along with bold comments necessary for implementation, please note that
for the data to be dynamically substituted:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "view_item_list", // Name of the event
ecommerce: {
item_list_id: "12345", // List ID
products
item_list_name: "CATEGORY OF THE WEEK", // Name of the list
products
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>
13. view_promotion
The event of displaying the promotion located under the promotional banner with
home page. Below is the script with bold comments
necessary for implementation, make sure that the data is substituted
dynamically:
<script>
dataLayer.push({ ecommerce: null }); // Deletes the dataLayer
from the previous event
dataLayer.push({
event: "view_promotion", // Event name
ecommerce: {
creative_name: "Summer Banner", // Banner name
promotion_id: "12345", // Promotion ID
promotion_name: "Summer Sale", // Promotion name
items: [
{
item_id: "12345", // Product ID
item_name: "R25 Beach Ball", // Product name
item_brand: "Nike", // Product brand (optional)
item_category: "Beach Balls", // Category
product
item_variant: "Black", // Product variant (if
present, optional)
price: 22.00, // Product price
quantity: 2 // Amount of products in the cart
}
]
}
});
</script>

 

Edited by sylwekb
Supplementing the content (see edit history)
Link to comment
Share on other sites

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...