anyone setup google dynamic remarketing and care to share how they implemented it?
EDIT: There's a plugin: https://www.zen-cart.com/downloads.php?do=file&id=1883
Printable View
anyone setup google dynamic remarketing and care to share how they implemented it?
EDIT: There's a plugin: https://www.zen-cart.com/downloads.php?do=file&id=1883
Hi,
I did it once.
I simply added a remarketing pixel to the common/tpl_footer.php file on my template
and another remarketing pixel to the templates/tpl_checkout_success_default.php file
to untarget people who converted.
that seems to be standard remarketing vs. the new since june dynamic one
this is the code,
trying to figure out what files to modify since variables vary due to page typeCode:<!-- Google Code for Remarketing Tag -->
<!--------------------------------------------------
Remarketing tags may not be associated with personally identifiable information or placed on pages related to sensitive categories. See more information and instructions on how to setup the tag on: http://google.com/ads/remarketingsetup
--------------------------------------------------->
<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: 'REPLACE_WITH_VALUE',
ecomm_pagetype: 'REPLACE_WITH_VALUE',
ecomm_totalvalue: 'REPLACE_WITH_VALUE',
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxxx;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1070392677/?value=0&guid=ON&script=0"/>
</div>
</noscript>
The goal is to deploy the following tags and corresponding parameters:
Page type Remarketing tag Conversion Tracking tag
Home ecomm_pagetype=home
ecomm_prodid=
ecomm_totalvalue= Not firing
Category ecomm_pagetype=category
ecomm_prodid=
ecomm_totalvalue= Not firing
Product ecomm_pagetype=product
ecomm_prodid=
ecomm_totalvalue= Not firing
Cart ecomm_pagetype=cart
ecomm_prodid=
ecomm_totalvalue= Not firing
Purchase Confirmation ecomm_pagetype=purchase
ecomm_prodid=
ecomm_totalvalue= value
All other pages ecomm_pagetype=siteview
ecomm_prodid=
ecomm_totalvalue= Not firing
I installed the Google Dynamic Remarketing Mod https://www.zen-cart.com/downloads.php?do=file&id=1883
It does not seem to be picking up the products_id and putting them in ecomm_prodid
Also the value seems a bit hit and miss.
I too have downloaded the Google Dynamic Remarketing mod and it isnt filling ecomm_prodid.
Maybe because I now realise that I have v1.3.9h and the module is for v1.5.0
Everything is fine with the coding apart from not picking up the product id.
Is it as simple as a one line piece of coding to pick up the product id ?
Can anyone help with a piece of coding ?
solved this:- I changed this line in the Google Dynamic Remarketing Mod ...
From this ... ecomm_prodid: " . $jsecomm_prodid . ",
to this ecomm_prodid: \"" . $_GET['products_id'] . "\",
I have no understanding of php coding but came up with this and it works ok.
Thanks it is a step it the right direction. Just need to get it to pick up the model numbers of items in the cart now.
Caution should be used when making changes such as this where the $_GET parameter is brought inline with other code. It should be sanitized first. Under this method, additional code could be provided to the browser uri that could cause the software to crash and expose information about the system or software.
An almost better option would be to upgrade to the latest ZC which is also more secure in general.
Did anybody get any joy on this?
I'm trying to use the same module and it is only managing to correctly fire the 'page type' field, the other 2 ('page id' and 'total value') do not work at all.
If I use the code directly from Google (below), what values do I need to replace to get Zen Cart to fill out for me?
If I can figure out what code to replace I'm happy to add this directly to the product info page myself and not use the module at all. Searching the forums doesn't give me any clues at all.PHP Code:
<script type="text/javascript">
var google_tag_params = {
ecomm_prodid: 'REPLACE_WITH_VALUE',
ecomm_pagetype: 'REPLACE_WITH_VALUE',
ecomm_totalvalue: 'REPLACE_WITH_VALUE',
};
</script>
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = *********;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/*********/?value=0&guid=ON&script=0"/>
</div>
</noscript>
I did try the GET parameter suggestion from this thread and that does indeed work, but the last poster mentioned its not 100% secure so I've not used it.
Cheers,
dp
After a weekend of hair pulling, I'm all out of ideas on what parameters to change to get this to work. :dontgetit
I'm bodging this up with all sorts of code - but I'm struggling to get the product_id changed to product_model as this is what we use in Google Adwords, does anyone know to edit the module to fix this? The module creator has dropped off the planet it seems.
Where $products_id has been assigned to a sanitized value of the products_id.Code:$model_query = "select products_model from products where products_id = :products_id:";
$model_query = $db->bindVars($model_query, ':products_id:', $products_id, 'integer');
$model = $db->Execute($model_query);
Thanks MC12345678,
I'm trying to change the module / plugin so it spits out the model name rather than the internal Zen Cart ID number.
I've played with what you've sent but I can't get it to work within the module at this point.
Well... What I provided was a way to obtain the products_model data if the products unique id.is/was known, not a specific set of code customized to the plugin... There may need to be a
In the function that the above is included. What issue(s) was had when trying to use it? Have you tried to capture the results in some other method? Either by displaying data or capturing it in a variable to be displayed as necessary?Code:global $db;
Sorry for the confusion MC12345678.
I've been trying to get the module working from the start, it only seemed to output the correct page type, with the product ID and product price not working.
I've managed to get it working for the product page with hard-coding amendments, but the cart page is still outputting the product ID rather than the model number that matches what we have in Google Adwords already set up (product feeds and campaigns).
Doing what I've done on the product page on the cart page doesn't work, for whatever reason. Another added issue is that I need the cart page to add up all the product prices together, and have all the model numbers listed and separated by a comma - which in fairness it is actually doing correctly. So if I could fudge the 'product_id' element for 'product_model' then this would give me what I need.
Sadly I'm not an expert coder, and I admit I'm struggling to get the module to do what I want. The dev abandoned it a while ago I think which is a shame as the remarketing element of Google Adwords is ideal for e-commerce stores and I can't believe that there aren't more people / stores on Zen wanting this module.
Thanks for your help so far, it is much appreciated.
dp
Update:
Google have themselves recommended that we change the feeds/GA account settings to use the internal Zen ID rather than the model number just to get this moving and live.
This is probably the quickest way to get the remarketing live and generating £££ for us.
dp
Did you figure this out tbaquatics?
:-)
Zencart 1.5.4
Dynamic Remarketing Plugin: V1.5.0
I am trying to use Google Dynamic Remarketing plugin but I am getting an error in my analytics reports.
Error: Your "ecomm_prodid” is not working correctly
Without this parameter, your dynamic ads won't be tailored to visitors' activity on your website.
I tried some of the suggestions in this thread for example
From this ... ecomm_prodid: " . $jsecomm_prodid . ",
to this ecomm_prodid: \"" . $_GET['products_id'] . "\",
But with no results. Can someone assist me or lead me in the right direction on getting Google dyamic remarketing working properly.
Thank you,
Chad
I have tried this mod (v1.5.4) not sure if it should work or not but.....
If I already have the google analytics mod installed, should I be removing it for the remarketing Tag to work?
I get 3 errors.
Conversion id not set
No HTTP response detected ?
Number field should not be quoted: 'ecomm_totalvalue'
Candleman
I am having the same issue on zencart 1.5.4.
Just an fyi I have google anaytics installed correctly and all seems good.. So i would not remove that plugin.
the remarketing tag as mentioned in my previous post is the issue regarding the jsecomm_prodid error.
If someone could assist us or lead us in the right direction i would greatly appreciate it.
I found this today but it's completely over my head.
https://www.zen-cart.com/content.php...els-to-my-site
I'm looking deeper into tag manager as I'm also looking to introduce Facebook pixel as well. The beauty of tag manager is that code can be altered via that instead of the zencart code.
Ideally i need a tag on every page and not just the checkout page.
Right here is where I am.
I have added the tag manager code onto the file includes/templates/MYTEMPLATE/common/tpl_main_page.php
I have also gone into my admin/configuration/Google analytics and DISABLED IT
I have added into Google tag manager (GMT from now on) a tag called universal analytics.
New, product analytics, tag type analytics, configure enter tracking ID ua-xxxxxxxx and track type page view. Fire on all pages.
Then again in GTM add a variable under new. Constant and in the value add your GTM code.
Now, using chrome as a browser (important) I have added a widget onto the browser called Google tag assistant. This then tests your website to see if the tag is present and what it sees.
I have loaded my Google analytics as well and can see using the real time reporting that I'm on my website.
Hope this helps
I am getting this:
ecomm_prodid: "",
ecomm_pagetype: "product",
ecomm_totalvalue: ""
What do I need to change in the original module to get a product id and total value instead of only empty quotes?
thx
I spent some time updating this module to be able to report based on ID or Model Number, and to detect product details more accurately on various pages.
If you were using the prior version, see the download page for the simple upgrade instructions.
https://www.zen-cart.com/downloads.php?do=file&id=1883
Thank you for the upgrade, really appreciate your dedication and your support.
zencart 1.5.8
php 8.1
I made some adjustments on this script to work with the updated analytics. The script is working great. The only question I have is there a way to ignore ez-pages. Does anyone have an idea on how to ignore the e-zpages or url's with the ids
Code:<?php
// Google Remarketing
// Dynamic Remarketing tracking code
// For Zen-Cart 1.5
// Author: Stef van Dijk - vandijkstef.nl
// This module is delivered as is, without any warranty
// Feel free to use and edit this module
// Licensed: GPL - http://www.gnu.org/licenses/licenses.html#GPL
// NOTE: This script only handles products identified by ID or by model-number.
// It does NOT differentiate products by attribute, nor by other properties such as custom fields like SKU, etc.
// Google conversion ID -- Replace AW-xxxxxxxxxx with your own ID received from Google:
$ga_conversion_id = 'AW-xxxxxxxxxx';
$product_identifier = 'id'; // can be 'id' or 'model', for the store's product_id or product_model_number respectively
// Pages to ignore
$pages_to_ignore = array(
'account', 'account_edit', 'account_history', 'account_history_info', 'account_newsletters',
'account_notifications', 'account_password', 'address_book', 'address_book_process',
'advanced_search', 'ask_a_question', 'checkout_confirmation', 'checkout_payment',
'checkout_payment_address', 'checkout_process', 'checkout_shipping', 'checkout_shipping_address',
'cookie_usage', 'create_account', 'create_account_success', 'customers_authorization',
'discount_coupon', 'down_for_maintenance', 'download', 'download_time_out', 'gv_redeem',
'gv_send', 'info_shopping_cart', 'login', 'logoff', 'page_2', 'page_3', 'page_4',
'page_not_found', 'password_forgotten', 'payer_auth_auth', 'payer_auth_frame',
'payer_auth_verifier', 'popup_attributes_qty_prices', 'popup_coupon_help', 'popup_cvv_help',
'popup_image', 'popup_image_additional', 'popup_search_help', 'popup_shipping_estimator',
'product_reviews_write', 'redirect', 'shippinginfo', 'ssl_check', 'time_out', 'unsubscribe','search', 'checkout_one','checkout_one_confirmation','site_map','contact_us',
);
// Check if the current page is in the ignore list
if (in_array($current_page_base, $pages_to_ignore)) {
return;
}
// DO NOT CHANGE BELOW
if (empty($ga_conversion_id) || $ga_conversion_id === '123456789') {
return;
}
// Product IDs array
$ecomm_prodid = array();
$ecomm_totalvalue = 0;
$ecomm_pagetype = 'other';
// If on a product page, get the product id
if ($current_page_base === 'product_info') {
if (!empty($_GET['products_id'])) {
$product_id = (int)$_GET['products_id'];
$ecomm_prodid[] = (string)$product_id;
// Get product price
$product_price_html = zen_get_products_display_price($product_id);
// Use regex to extract the price
if (preg_match('/<span[^>]*class="[^"]*productSpecialPrice[^"]*"[^>]*>\$([\d,]+\.\d{2})<\/span>/', $product_price_html, $matches)) {
$ecomm_totalvalue = (float)str_replace(',', '', $matches[1]);
} elseif (preg_match('/<span[^>]*class="[^"]*normalprice[^"]*"[^>]*>\$([\d,]+\.\d{2})<\/span>/', $product_price_html, $matches)) {
$ecomm_totalvalue = (float)str_replace(',', '', $matches[1]);
}
}
}
// If on the shopping cart page, add the cart's items to the array
if ($current_page_base === 'shopping_cart') {
$cart_products = $_SESSION['cart']->get_products();
foreach ($cart_products as $product) {
if ($product_identifier === 'id') {
$ecomm_prodid[] = (string)(int)$product['id'];
} elseif ($product_identifier === 'model') {
$ecomm_prodid[] = (string)$product['model'];
}
}
$ecomm_totalvalue = $_SESSION['cart']->show_total();
}
// If this is checkout_success, set the products and total value from order
if ($current_page_base === 'checkout_success') {
// Retrieve the order ID from the session or the URL
$order_id = isset($_SESSION['order_number_created']) ? (int)$_SESSION['order_number_created'] : (isset($_GET['order_id']) ? (int)$_GET['order_id'] : 0);
if ($order_id > 0) {
// Retrieve the products and total value from the order
$order = $db->Execute("SELECT products_id, products_model, final_price, products_quantity FROM " . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = " . $order_id);
while (!$order->EOF) {
if ($product_identifier === 'id') {
$ecomm_prodid[] = (string)(int)$order->fields['products_id'];
} elseif ($product_identifier === 'model') {
$ecomm_prodid[] = (string)$order->fields['products_model'];
}
$ecomm_totalvalue += (float)$order->fields['final_price'] * (int)$order->fields['products_quantity'];
$order->MoveNext();
}
}
}
// Get product IDs from listing or search result pages
if (empty($ecomm_prodid) && !empty($listing_sql)) {
$products = $db->Execute($listing_sql);
while (!$products->EOF) {
if ($product_identifier === 'id') {
$ecomm_prodid[] = (string)(int)$products->fields['products_id'];
} elseif ($product_identifier === 'model' && !empty($products->fields['products_model'])) {
$ecomm_prodid[] = (string)$products->fields['products_model'];
}
$products->MoveNext();
}
}
// Map pages to page types
$page_map = array(
'search_result' => 'searchresults',
'index' => 'category',
'product_info' => 'product',
'shopping_cart' => 'cart',
'checkout_success' => 'purchase',
);
if ($this_is_home_page) {
$ecomm_pagetype = 'home';
} elseif (array_key_exists($current_page_base, $page_map)) {
$ecomm_pagetype = $page_map[$current_page_base];
}
// Prepare tag parameters
$tag_params = array(
'ecomm_prodid' => $ecomm_prodid,
'ecomm_pagetype' => (string)$ecomm_pagetype,
'ecomm_totalvalue' => !empty($ecomm_totalvalue) ? round((float)$ecomm_totalvalue, 2) : 0,
);
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo htmlspecialchars($ga_conversion_id, ENT_QUOTES, 'UTF-8'); ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?php echo htmlspecialchars($ga_conversion_id, ENT_QUOTES, 'UTF-8'); ?>');
// Remarketing tag setup
gtag('event', 'purchase', <?php echo json_encode($tag_params, JSON_NUMERIC_CHECK); ?>);
</script>
Add to the end of $pages_to_ignore
, 'page'
perfect. If anyone is interested in getting the remarketing script this is my final result
Code:<?php
// Google Remarketing
// Dynamic Remarketing tracking code
// For Zen-Cart 1.5
// Author: Stef van Dijk - vandijkstef.nl
// This module is delivered as is, without any warranty
// Feel free to use and edit this module
// Licensed: GPL - http://www.gnu.org/licenses/licenses.html#GPL
// NOTE: This script only handles products identified by ID or by model-number.
// It does NOT differentiate products by attribute, nor by other properties such as custom fields like SKU, etc.
// Google conversion ID -- Replace AW-xxxxxxxxxx with your own ID received from Google:
$ga_conversion_id = 'AW-xxxxxxxxxx';
$product_identifier = 'id'; // can be 'id' or 'model', for the store's product_id or product_model_number respectively
// Pages to ignore
$pages_to_ignore = array(
'account', 'account_edit', 'account_history', 'account_history_info', 'account_newsletters',
'account_notifications', 'account_password', 'address_book', 'address_book_process',
'advanced_search', 'ask_a_question', 'checkout_confirmation', 'checkout_payment',
'checkout_payment_address', 'checkout_process', 'checkout_shipping', 'checkout_shipping_address',
'cookie_usage', 'create_account', 'create_account_success', 'customers_authorization',
'discount_coupon', 'down_for_maintenance', 'download', 'download_time_out', 'gv_redeem',
'gv_send', 'info_shopping_cart', 'login', 'logoff', 'page_2', 'page_3', 'page_4',
'page_not_found', 'password_forgotten', 'payer_auth_auth', 'payer_auth_frame',
'payer_auth_verifier', 'popup_attributes_qty_prices', 'popup_coupon_help', 'popup_cvv_help',
'popup_image', 'popup_image_additional', 'popup_search_help', 'popup_shipping_estimator',
'product_reviews_write', 'redirect', 'shippinginfo', 'ssl_check', 'time_out', 'unsubscribe','search', 'checkout_one','checkout_one_confirmation','page',
);
// Check if the current page is in the ignore list
if (in_array($current_page_base, $pages_to_ignore)) {
return;
}
// DO NOT CHANGE BELOW
if (empty($ga_conversion_id) || $ga_conversion_id === '123456789') {
return;
}
// Product IDs array
$ecomm_prodid = array();
$ecomm_totalvalue = 0;
$ecomm_pagetype = 'other';
// If on a product page, get the product id
if ($current_page_base === 'product_info') {
if (!empty($_GET['products_id'])) {
$product_id = (int)$_GET['products_id'];
$ecomm_prodid[] = (string)$product_id;
// Get product price
$product_price_html = zen_get_products_display_price($product_id);
// Use regex to extract the price
if (preg_match('/<span[^>]*class="[^"]*productSpecialPrice[^"]*"[^>]*>\$([\d,]+\.\d{2})<\/span>/', $product_price_html, $matches)) {
$ecomm_totalvalue = (float)str_replace(',', '', $matches[1]);
} elseif (preg_match('/<span[^>]*class="[^"]*normalprice[^"]*"[^>]*>\$([\d,]+\.\d{2})<\/span>/', $product_price_html, $matches)) {
$ecomm_totalvalue = (float)str_replace(',', '', $matches[1]);
}
}
}
// If on the shopping cart page, add the cart's items to the array
if ($current_page_base === 'shopping_cart') {
$cart_products = $_SESSION['cart']->get_products();
foreach ($cart_products as $product) {
if ($product_identifier === 'id') {
$ecomm_prodid[] = (string)(int)$product['id'];
} elseif ($product_identifier === 'model') {
$ecomm_prodid[] = (string)$product['model'];
}
}
$ecomm_totalvalue = $_SESSION['cart']->show_total();
}
// If this is checkout_success, set the products and total value from order
if ($current_page_base === 'checkout_success') {
// Retrieve the order ID from the session or the URL
$order_id = isset($_SESSION['order_number_created']) ? (int)$_SESSION['order_number_created'] : (isset($_GET['order_id']) ? (int)$_GET['order_id'] : 0);
if ($order_id > 0) {
// Retrieve the products and total value from the order
$order = $db->Execute("SELECT products_id, products_model, final_price, products_quantity FROM " . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = " . $order_id);
while (!$order->EOF) {
if ($product_identifier === 'id') {
$ecomm_prodid[] = (string)(int)$order->fields['products_id'];
} elseif ($product_identifier === 'model') {
$ecomm_prodid[] = (string)$order->fields['products_model'];
}
$ecomm_totalvalue += (float)$order->fields['final_price'] * (int)$order->fields['products_quantity'];
$order->MoveNext();
}
}
}
// Get product IDs from listing or search result pages
if (empty($ecomm_prodid) && !empty($listing_sql)) {
$products = $db->Execute($listing_sql);
while (!$products->EOF) {
if ($product_identifier === 'id') {
$ecomm_prodid[] = (string)(int)$products->fields['products_id'];
} elseif ($product_identifier === 'model' && !empty($products->fields['products_model'])) {
$ecomm_prodid[] = (string)$products->fields['products_model'];
}
$products->MoveNext();
}
}
// Map pages to page types
$page_map = array(
'search_result' => 'searchresults',
'index' => 'category',
'product_info' => 'product',
'shopping_cart' => 'cart',
'checkout_success' => 'purchase',
);
if ($this_is_home_page) {
$ecomm_pagetype = 'home';
} elseif (array_key_exists($current_page_base, $page_map)) {
$ecomm_pagetype = $page_map[$current_page_base];
}
// Prepare tag parameters
$tag_params = array(
'ecomm_prodid' => $ecomm_prodid,
'ecomm_pagetype' => (string)$ecomm_pagetype,
'ecomm_totalvalue' => !empty($ecomm_totalvalue) ? round((float)$ecomm_totalvalue, 2) : 0,
);
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo htmlspecialchars($ga_conversion_id, ENT_QUOTES, 'UTF-8'); ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?php echo htmlspecialchars($ga_conversion_id, ENT_QUOTES, 'UTF-8'); ?>');
// Remarketing tag setup
gtag('event', 'purchase', <?php echo json_encode($tag_params, JSON_NUMERIC_CHECK); ?>);
</script>
I have a question
I noticed on the checkout success page the script does not capture the shipping or tax in the "ecomm_totalvalue".
I am not sure if we are supposed to even collect that information. Any one have any advice...
I also made some other revisions to the script.
Code:<?php
// Google Remarketing
// Dynamic Remarketing tracking code
// For Zen-Cart 1.5
// Author: Stef van Dijk - vandijkstef.nl
// This module is delivered as is, without any warranty
// Feel free to use and edit this module
// Licensed: GPL - http://www.gnu.org/licenses/licenses.html#GPL
// NOTE: This script only handles products identified by ID or by model-number.
// It does NOT differentiate products by attribute, nor by other properties such as custom fields like SKU, etc.
// Google conversion ID -- Replace AW-xxxxxxxxxx with your own ID received from Google:
$ga_conversion_id = 'AW-xxxxxxxxxx';
$product_identifier = 'id'; // can be 'id' or 'model', for the store's product_id or product_model_number respectively
// Pages to ignore
$pages_to_ignore = [
'account', 'account_edit', 'account_history', 'account_history_info', 'account_newsletters',
'account_notifications', 'account_password', 'address_book', 'address_book_process',
'advanced_search', 'ask_a_question', 'checkout_confirmation', 'checkout_payment',
'checkout_payment_address', 'checkout_process', 'checkout_shipping', 'checkout_shipping_address',
'cookie_usage', 'create_account', 'create_account_success', 'customers_authorization',
'discount_coupon', 'down_for_maintenance', 'download', 'download_time_out', 'gv_redeem',
'gv_send', 'info_shopping_cart', 'login', 'logoff', 'page_2', 'page_3', 'page_4',
'page_not_found', 'password_forgotten', 'payer_auth_auth', 'payer_auth_frame',
'payer_auth_verifier', 'popup_attributes_qty_prices', 'popup_coupon_help', 'popup_cvv_help',
'popup_image', 'popup_image_additional', 'popup_search_help', 'popup_shipping_estimator',
'product_reviews_write', 'redirect', 'shippinginfo', 'ssl_check', 'time_out', 'unsubscribe',
'search', 'checkout_one', 'checkout_one_confirmation', 'order_status', 'privacy', 'conditions',
'site_map', 'contact_us', 'returns', 'page'
];
// Check if the current page is in the ignore list
if (in_array($current_page_base, $pages_to_ignore)) {
return;
}
// DO NOT CHANGE BELOW
if (empty($ga_conversion_id) || $ga_conversion_id === '123456789') {
return;
}
// Product IDs array
$ecomm_prodid = [];
$ecomm_totalvalue = 0;
$ecomm_pagetype = 'other';
// Helper function to get product price
function getProductPrice($product_id) {
$product_price_html = zen_get_products_display_price($product_id);
if (preg_match('/<span[^>]*class="[^"]*productSpecialPrice[^"]*"[^>]*>\$([\d,]+\.\d{2})<\/span>/', $product_price_html, $matches)) {
return (float)str_replace(',', '', $matches[1]);
} elseif (preg_match('/<span[^>]*class="[^"]*normalprice[^"]*"[^>]*>\$([\d,]+\.\d{2})<\/span>/', $product_price_html, $matches)) {
return (float)str_replace(',', '', $matches[1]);
}
return 0;
}
// If on a product page, get the product id
if ($current_page_base === 'product_info' && !empty($_GET['products_id'])) {
$product_id = (int)$_GET['products_id'];
$ecomm_prodid[] = (string)$product_id;
$ecomm_totalvalue = getProductPrice($product_id);
}
// If on the shopping cart page, add the cart's items to the array
if ($current_page_base === 'shopping_cart') {
$cart_products = $_SESSION['cart']->get_products();
foreach ($cart_products as $product) {
$ecomm_prodid[] = $product_identifier === 'id' ? (string)(int)$product['id'] : (string)$product['model'];
}
$ecomm_totalvalue = $_SESSION['cart']->show_total();
}
// If this is checkout_success, set the products and total value from order
if ($current_page_base === 'checkout_success') {
$order_id = isset($_SESSION['order_number_created']) ? (int)$_SESSION['order_number_created'] : (isset($_GET['order_id']) ? (int)$_GET['order_id'] : 0);
if ($order_id > 0) {
$order = $db->Execute("SELECT products_id, products_model, final_price, products_quantity FROM " . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = " . $order_id);
while (!$order->EOF) {
$ecomm_prodid[] = $product_identifier === 'id' ? (string)(int)$order->fields['products_id'] : (string)$order->fields['products_model'];
$ecomm_totalvalue += (float)$order->fields['final_price'] * (int)$order->fields['products_quantity'];
$order->MoveNext();
}
}
}
// Get product IDs from listing or search result pages
if (empty($ecomm_prodid) && !empty($listing_sql)) {
$products = $db->Execute($listing_sql);
while (!$products->EOF) {
$ecomm_prodid[] = $product_identifier === 'id' ? (string)(int)$products->fields['products_id'] : (string)$products->fields['products_model'];
$products->MoveNext();
}
}
// Map pages to page types and corresponding event names
$page_map = [
'search_result' => ['page_type' => 'searchresults', 'event_name' => 'searchresults'],
'index' => ['page_type' => 'category', 'event_name' => 'category'],
'product_info' => ['page_type' => 'product', 'event_name' => 'product'],
'shopping_cart' => ['page_type' => 'cart', 'event_name' => 'cart'],
'checkout_success' => ['page_type' => 'purchase', 'event_name' => 'purchase'],
];
if ($this_is_home_page) {
$ecomm_pagetype = 'home';
} elseif (array_key_exists($current_page_base, $page_map)) {
$ecomm_pagetype = isset($page_map[$current_page_base]) ? $page_map[$current_page_base]['page_type'] : 'other';
}
// Prepare tag parameters
$tag_params = [
'ecomm_prodid' => $ecomm_prodid,
'ecomm_pagetype' => (string)$ecomm_pagetype,
'ecomm_totalvalue' => !empty($ecomm_totalvalue) ? round((float)$ecomm_totalvalue, 2) : 0,
];
// Get the correct event name based on $ecomm_pagetype
$event_name = isset($page_map[$current_page_base]) ? $page_map[$current_page_base]['event_name'] : 'other';
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo htmlspecialchars($ga_conversion_id, ENT_QUOTES, 'UTF-8'); ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?php echo htmlspecialchars($ga_conversion_id, ENT_QUOTES, 'UTF-8'); ?>');
// Remarketing tag setup
gtag('event', '<?php echo htmlspecialchars($event_name, ENT_QUOTES, 'UTF-8'); ?>', <?php echo json_encode($tag_params, JSON_NUMERIC_CHECK); ?>);
</script>
I did some revisions now it seems to be firing the mapping pages to page type.
I been having some issue with this script. I think finally got it to fire correctly.
If anything else should arise i will post.
Code:<?php
// Google Remarketing
// Dynamic Remarketing tracking code
// For Zen-Cart 1.5
// Author: Stef van Dijk - vandijkstef.nl
// This module is delivered as is, without any warranty
// Feel free to use and edit this module
// Licenced: GPL - http://www.gnu.org/licenses/licenses.html#GPL
// NOTE: This script only handles products identified by ID or by model-number.
// It does NOT differentiate products by attribute, nor by other properties such as custom fields like SKU etc
// Google conversion ID -- Replace AW-xxxxxxxxxx with your own ID received from Google:
$ga_conversion_id = 'AW-xxxxxxxxx';
$product_identifier = 'id'; // can be 'id' or 'model', for the store's product_id or product_model_number respectively.
// PUT YOUR CUSTOMIZATIONS ABOVE. That's all.
$pages_to_ignore = array(
'account', 'account_edit', 'account_history', 'account_history_info', 'account_newsletters',
'account_notifications', 'account_password', 'address_book', 'address_book_process',
'advanced_search', 'ask_a_question', 'checkout_confirmation', 'checkout_payment',
'checkout_payment_address', 'checkout_process', 'checkout_shipping', 'checkout_shipping_address',
'cookie_usage', 'create_account', 'create_account_success', 'customers_authorization',
'discount_coupon', 'down_for_maintenance', 'download', 'download_time_out', 'gv_redeem',
'gv_send', 'info_shopping_cart', 'login', 'logoff', 'page_2', 'page_3', 'page_4',
'page_not_found', 'password_forgotten', 'payer_auth_auth', 'payer_auth_frame',
'payer_auth_verifier', 'popup_attributes_qty_prices', 'popup_coupon_help', 'popup_cvv_help',
'popup_image', 'popup_image_additional', 'popup_search_help', 'popup_shipping_estimator',
'product_reviews_write', 'redirect', 'shippinginfo', 'ssl_check', 'time_out', 'unsubscribe','search', 'checkout_one','checkout_one_confirmation','site_map','contact_us',
);
if (in_array($current_page_base, $pages_to_ignore)) return;
// DO NOT CHANGE BELOW
if (empty($ga_conversion_id) || $ga_conversion_id === '123456789') return;
// DO NOT CHANGE BELOW!
if ($ga_conversion_id === 'AW-xxxxxxxxxx') {
if (defined('AW-xxxxxxxxx') && !empty(AW-xxxxxxxxx)) {
$ga_conversion_id = AW-xxxxxxxxxx;
} else {
return;
}
}
// Product_ids
$ecomm_prodid = array();
// Var to save value
$ecomm_totalvalue = 0;
// If on a product page, get the product id
if ($product_identifier === 'id' && !empty($_GET['products_id'])) {
array_push($ecomm_prodid, (string)(int)$_GET['products_id']);
} elseif ($product_identifier === 'model' && !empty($products_model)) {
array_push($ecomm_prodid, (string)$products_model);
}
// If on the shopping_cart page, add the cart's items to the array
if ($current_page_base === 'shopping_cart') {
$cart_products = $_SESSION['cart']->get_products();
foreach ($cart_products as $the_product) {
if ($product_identifier === 'id') {
array_push($ecomm_prodid, (string)(int)$the_product['id']);
} elseif ($product_identifier === 'model') {
array_push($ecomm_prodid, (string)$the_product['model']);
}
}
}
// If this is checkout_success (completed a purchase), we set the products so the targeting can be marked as sold
if ($current_page_base === 'checkout_success') {
if ($product_identifier === 'id' && !empty($order_summary['products_ordered_ids'])) {
$data = $order_summary['products_ordered_ids'];
} elseif ($product_identifier === 'model' && !empty($order_summary['products_ordered_models'])) {
$data = $order_summary['products_ordered_models'];
} else {
// this should never happen unless the customer is refreshing the checkout-success page
// but we don't want to double-track conversions, so we exit here in that case
return;
}
if (!empty($data)) {
foreach (explode('|', $data) as $the_product) {
array_push($ecomm_prodid, (string)$the_product);
}
}
}
// Product Listing (category) pages, and search results pages
if (empty($ecomm_prodid) && !empty($listing_sql)) {
if (!empty($listing)) {
$data = $listing;
} else if ($current_page_base === 'advanced_search_result' && !empty($result)) {
$data = $result;
}
if (!empty($data)) {
foreach ($data as $the_product) {
if ($product_identifier === 'id') {
array_push($ecomm_prodid, (string)(int)$the_product['products_id']);
} elseif ($product_identifier === 'model' && !empty($the_product['products_model'])) {
array_push($ecomm_prodid, (string)$the_product['products_model']);
}
}
}
}
// Map pages to page types.
// Possible types: home, searchresults, category, product, cart, purchase, other.
// Fallback/default if not in this list = other
$page_map = array(
'advanced_search_result' => 'searchresults',
'index' => 'category',
'product_info' => 'product',
'product_free_shipping_info' => 'product',
'document_product_info' => 'product',
'product_music_info' => 'product',
'shopping_cart' => 'cart',
'checkout_success' => 'purchase',
);
// Set the pagetype to specific page, otherwise "other" will be pushed
if ($this_is_home_page) {
$ecomm_pagetype = 'home';
} elseif (array_key_exists($current_page_base, $page_map)) {
$ecomm_pagetype = $page_map[$current_page_base];
} else {
$ecomm_pagetype = 'other';
}
// Get the total value - Value stays empty if page is not product or cart/payment
if ($ecomm_pagetype === 'cart' || $ecomm_pagetype === 'purchase') {
$ecomm_totalvalue = $_SESSION['cart']->show_total();
} elseif ($ecomm_pagetype === 'product') {
$product_price = zen_get_products_display_price((int)$_GET['products_id']);
$ecomm_totalvalue = preg_replace('/[^\d,.]/', '', $product_price);
}
$tag_params = array(
'ecomm_prodid' => $ecomm_prodid,
'ecomm_pagetype' => (string)$ecomm_pagetype,
'ecomm_totalvalue' => !empty($ecomm_totalvalue) ? round($ecomm_totalvalue, 2) : 0,
);
// Variable block for Remarketing tag
echo '<script title="RemarketingData">
var google_tag_params = ' . json_encode($tag_params) . ';
</script>';
// Remarketing Tag
echo ' <script title="RemarketingTag">
/* <![CDATA[ */
var google_conversion_id = "' . $ga_conversion_id . '";
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script src="//www.googleadservices.com/pagead/conversion.js"></script>
<noscript><div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/' . $ga_conversion_id . '/?value=0&guid=ON&script=0">
</div></noscript>';