通过google tag manager或php实现自定义像素和电子商务集成

通过google tag manager或php实现自定义像素和电子商务集成,php,wordpress,woocommerce,tags,google-tag-manager,Php,Wordpress,Woocommerce,Tags,Google Tag Manager,晚上好,我有一个Woocommerce电子商店,我想集成一个附属网站的自定义像素代码,以跟踪产品的一些事件,如页面视图、类别视图、购买等。他们希望我将以下代码和说明集成到我的网站中: 页面浏览代码: <script> (function(f, a, s, h, i, o, n) {f['GlamiTrackerObject'] = i; f[i]=f[i]||function(){(f[i].q=f[i].q||[]).push(arguments)};o=a.createEleme

晚上好,我有一个Woocommerce电子商店,我想集成一个附属网站的自定义像素代码,以跟踪产品的一些事件,如页面视图、类别视图、购买等。他们希望我将以下代码和说明集成到我的网站中:

页面浏览代码:

<script>
(function(f, a, s, h, i, o, n) {f['GlamiTrackerObject'] = i;
f[i]=f[i]||function(){(f[i].q=f[i].q||[]).push(arguments)};o=a.createElement(s),
n=a.getElementsByTagName(s)[0];o.async=1;o.src=h;n.parentNode.insertBefore(o,n)
})(window, document, 'script', '//www.glami.gr/js/compiled/pt.js', 'glami');

glami('create', '5A5E5996B2A69C196F8C4BC9E7E55F41', 'gr');
glami('track', 'PageView');
</script>
glami('track', 'ViewContent', {
content_type: 'product',
item_ids: ['ADZXFLUX002'], // currently viewed product ID. Use the same ID as you use in the feed (ITEM_ID)
product_names: ['Adidas ZX Flux Power Red'] // currently viewed product name. Use the same names as you use in the feed (PRODUCTNAME).
});
glami('track', 'ViewContent', {
content_type: 'category',
item_ids: ['ADZXFLUX001', 'NRS02', 'NRS03', 'NRS04', 'NRS05', 'NRS06', 'NRS07', 'NRS08', 'NRS09', 'NRS10'], // currently viewed first 10 product IDs in the category. Use the same IDs as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red', 'Nike running shorts', ...] // currently viewed first 10 product names. Use the same names as you use in the feed (PRODUCTNAME).
category_id: 'ID_SHOES_001' // currently viewed category ID. Use the same category ID as you use in the feed (CATEGORY_ID)
category_text: 'Men | Shoes | Sneakers' // currently viewed category_text. Use the same category_text as you use in the feed (CATEGORYTEXT)
});
glami('track', 'Purchase', {
item_ids: ['ADZXFLUX002', 'NRS01'], // bought product IDs. Use the same IDs as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red', 'Nike running shorts'], // bought product names. Use the same names as you use in the feed (PRODUCTNAME).
value: 3490.00, // order value
currency: 'EUR', // order value currency
transaction_id: 'ORDER212' // order ID
});
查看内容(类别):

<script>
(function(f, a, s, h, i, o, n) {f['GlamiTrackerObject'] = i;
f[i]=f[i]||function(){(f[i].q=f[i].q||[]).push(arguments)};o=a.createElement(s),
n=a.getElementsByTagName(s)[0];o.async=1;o.src=h;n.parentNode.insertBefore(o,n)
})(window, document, 'script', '//www.glami.gr/js/compiled/pt.js', 'glami');

glami('create', '5A5E5996B2A69C196F8C4BC9E7E55F41', 'gr');
glami('track', 'PageView');
</script>
glami('track', 'ViewContent', {
content_type: 'product',
item_ids: ['ADZXFLUX002'], // currently viewed product ID. Use the same ID as you use in the feed (ITEM_ID)
product_names: ['Adidas ZX Flux Power Red'] // currently viewed product name. Use the same names as you use in the feed (PRODUCTNAME).
});
glami('track', 'ViewContent', {
content_type: 'category',
item_ids: ['ADZXFLUX001', 'NRS02', 'NRS03', 'NRS04', 'NRS05', 'NRS06', 'NRS07', 'NRS08', 'NRS09', 'NRS10'], // currently viewed first 10 product IDs in the category. Use the same IDs as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red', 'Nike running shorts', ...] // currently viewed first 10 product names. Use the same names as you use in the feed (PRODUCTNAME).
category_id: 'ID_SHOES_001' // currently viewed category ID. Use the same category ID as you use in the feed (CATEGORY_ID)
category_text: 'Men | Shoes | Sneakers' // currently viewed category_text. Use the same category_text as you use in the feed (CATEGORYTEXT)
});
glami('track', 'Purchase', {
item_ids: ['ADZXFLUX002', 'NRS01'], // bought product IDs. Use the same IDs as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red', 'Nike running shorts'], // bought product names. Use the same names as you use in the feed (PRODUCTNAME).
value: 3490.00, // order value
currency: 'EUR', // order value currency
transaction_id: 'ORDER212' // order ID
});
AddToCart

glami('track', 'AddToCart', {
item_ids: ['ADZXFLUX002'], // product ID currently added to a cart. Use the same ID as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red'], // product name currently added to a cart. Use the same names as you use in the feed (PRODUCTNAME).
value: 2495.00, // product price
currency: 'EUR' // product price currency
});
add_action('woocommerce_before_single_product', 'glami_pageview_single_product_code');
function glami_pageview_single_product_code(){
global $product;
$product_id = $product->get_id();
?>
  <script>
glami('track', 'ViewContent', {
content_type: 'product',
item_ids: ['<?php echo $product_id; ?>'], 
product_names: ['<?php echo $product->get_title(); ?>'] 
});
</script>
<?php
}
购买:

<script>
(function(f, a, s, h, i, o, n) {f['GlamiTrackerObject'] = i;
f[i]=f[i]||function(){(f[i].q=f[i].q||[]).push(arguments)};o=a.createElement(s),
n=a.getElementsByTagName(s)[0];o.async=1;o.src=h;n.parentNode.insertBefore(o,n)
})(window, document, 'script', '//www.glami.gr/js/compiled/pt.js', 'glami');

glami('create', '5A5E5996B2A69C196F8C4BC9E7E55F41', 'gr');
glami('track', 'PageView');
</script>
glami('track', 'ViewContent', {
content_type: 'product',
item_ids: ['ADZXFLUX002'], // currently viewed product ID. Use the same ID as you use in the feed (ITEM_ID)
product_names: ['Adidas ZX Flux Power Red'] // currently viewed product name. Use the same names as you use in the feed (PRODUCTNAME).
});
glami('track', 'ViewContent', {
content_type: 'category',
item_ids: ['ADZXFLUX001', 'NRS02', 'NRS03', 'NRS04', 'NRS05', 'NRS06', 'NRS07', 'NRS08', 'NRS09', 'NRS10'], // currently viewed first 10 product IDs in the category. Use the same IDs as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red', 'Nike running shorts', ...] // currently viewed first 10 product names. Use the same names as you use in the feed (PRODUCTNAME).
category_id: 'ID_SHOES_001' // currently viewed category ID. Use the same category ID as you use in the feed (CATEGORY_ID)
category_text: 'Men | Shoes | Sneakers' // currently viewed category_text. Use the same category_text as you use in the feed (CATEGORYTEXT)
});
glami('track', 'Purchase', {
item_ids: ['ADZXFLUX002', 'NRS01'], // bought product IDs. Use the same IDs as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red', 'Nike running shorts'], // bought product names. Use the same names as you use in the feed (PRODUCTNAME).
value: 3490.00, // order value
currency: 'EUR', // order value currency
transaction_id: 'ORDER212' // order ID
});

我有兴趣通过Google Tag Manager或主题php函数文件上的php集成代码。

您需要使用钩子。对于大多数代码来说,它相当简单,但是对于addtocart来说,它要复杂一些

页面浏览代码

add_action('wp_footer', 'glami_pageview_code');
function glami_pageview_code(){
?>
    <script>
(function(f, a, s, h, i, o, n) {f['GlamiTrackerObject'] = i;
f[i]=f[i]||function(){(f[i].q=f[i].q||[]).push(arguments)};o=a.createElement(s),
n=a.getElementsByTagName(s)[0];o.async=1;o.src=h;n.parentNode.insertBefore(o,n)
})(window, document, 'script', '//www.glami.gr/js/compiled/pt.js', 'glami');

glami('create', '5A5E5996B2A69C196F8C4BC9E7E55F41', 'gr');
glami('track', 'PageView');
</script>
<?php
}
购买…相同的方式,只是不同的挂钩

add_action('woocommerce_thankyou', 'glami_purchase_code', 10, 1);
function glami_purchase_code($order_id){
$order = new WC_Order($order_id);
// Use $order object to get all the information you need.

这是在my functions.php上实现它的最终代码吗?我真的不知道在你留下的字段中插入什么代码。我对我的答案进行了更多的编辑。。这里肯定有工作要做,这里的答案不能为你完成全部工作。无论如何,我已经为第一个和第二个代码请求添加了完整的代码,您可以在functions.php上使用这些代码,其余的您需要探索和完成。我理解这一点。他们告诉我我需要找到合适的钩子。不过还是谢谢你,也许有人能帮上点忙。