一、官方文档
https://help-ads.smartnews.com/linkonly/item-3930/#i3
二、兼容版本
Theme OS 1.0&2.0&2.1
三、操作流程
1. Smartnews 配置
1.1. 创建你的 Smartnews Pixel Event
- Go to Events tab in Ads Manager and select Create new Pixel.
2. Shopline配置
2.1. 安装自定义代码应用, 点击添加代码
2.2. 触发页面全选,插入位置底部
2.3. 将以下代码复制入代码内容, 注意修改自己的 **[pixel ID]**
主题 2.1
<script>
!function(){if(window.SmartnewsAds=window.SmartnewsAds||{},!window.SmartnewsAds.p){var e=window.SmartnewsAds.p=function(){e.callMethod?e.callMethod.apply(e,arguments):e.queue.push(arguments)};e.push=e,e.version="1.0.1",e.queue=[];var n=document.createElement("script");n.async=!0,n.src="https://cdn.smartnews-ads.com/i/pixel.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(n,s)}}();
console.log('Start Smartnews Pixel Snippet PageView')
SmartnewsAds.p("[pixel ID]", "PageView");
(function () {
const originalFetch = window.fetch;
window.fetch = function (...args) {
return new Promise((resolve, reject) => {
originalFetch
.apply(this, args)
.then((response) => {
try {
const clone = response.clone();
if ((args[0] && args[0].url && args[0].url.includes("/cart/add")) || (args[0] && args[0] === "/cart/add")) {
console.log('Start Smartnews Pixel Snippet add_to_cart')
SmartnewsAds.p("[pixel ID]", "AddToCart");
}
resolve(response);
} catch (error) {
console.error("Error processing add_to_cart batch request", error);
}
})
.catch((error) => {
reject(error);
});
});
};
const originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function (body) {
const method = this._method;
const url = this._url;
if (method === "POST" && url === "/leproxy/api/carts/cart/batch/add") {
try {
console.log('Start Smartnews Pixel Snippet add_to_cart')
SmartnewsAds.p("[pixel ID]", "AddToCart");
} catch (error) {
console.error("Error processing add_to_cart batch request", error);
}
}
return originalSend.apply(this, arguments);
};
})();
{{#if @root.checkout}}
console.log('Start Smartnews Pixel Snippet initiate_checkout')
SmartnewsAds.p("[pixel ID]", "InitiateCheckout");
{{/if}}
{{#if @root.thankyou}}
console.log('Start Smartnews Pixel Snippet purchase')
SmartnewsAds.p("[pixel ID]", "Purchase");
{{/if}}
</script>
主题 1.0&2.0
<script>
!function(){if(window.SmartnewsAds=window.SmartnewsAds||{},!window.SmartnewsAds.p){var e=window.SmartnewsAds.p=function(){e.callMethod?e.callMethod.apply(e,arguments):e.queue.push(arguments)};e.push=e,e.version="1.0.1",e.queue=[];var n=document.createElement("script");n.async=!0,n.src="https://cdn.smartnews-ads.com/i/pixel.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(n,s)}}();
console.log('Start Smartnews Pixel Snippet PageView')
SmartnewsAds.p("[pixel ID]", "PageView");
window.Shopline.event?.on('DataReport::AddToCart', function (payload) {
SmartnewsAds.p("[pixel ID]", "AddToCart");
})
{{#if @root.checkout}}
console.log('Start Smartnews Pixel Snippet initiate_checkout')
SmartnewsAds.p("[pixel ID]", "InitiateCheckout");
{{/if}}
{{#if @root.thankyou}}
console.log('Start Smartnews Pixel Snippet purchase')
SmartnewsAds.p("[pixel ID]", "Purchase");
{{/if}}
</script>


