Twitter事件代码和基础跟踪代码的优化
1. Twitter Conversion Tracking Base Code
位置: 放在网页的
<head>标签内。原因: 这个代码是用于加载 Twitter 的跟踪脚本并初始化追踪功能,因此需要尽早加载以确保页面的其他部分可以正常追踪。
<!-- Twitter conversion tracking base code -->
<script>
!function(e,t,n,s,u,a){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);
},s.version='1.1',s.queue=[],u=t.createElement(n),u.async=!0,u.src='https://static.ads-twitter.com/uwt.js',
a=t.getElementsByTagName(n)[0],a.parentNode.insertBefore(u,a))}(window,document,'script');
twq('config','on6og');
</script>
<!-- End Twitter conversion tracking base code -->
2. Twitter Conversion Tracking Event Code
位置: 放在触发特定转化事件的页面(如订单确认页、购买成功页)的
</body>上,或者动态事件发生时执行。原因: 这个代码用于跟踪特定的转化事件(如购买、注册等),因此需要在发生这些行为的页面或事件中加载。
<!-- Twitter conversion tracking event code -->
<script type="text/javascript">
// Insert Twitter Event ID
twq('event', 'tw-oncki-onl3g', {
value: null, // use this to pass the value of the conversion (e.g. 5.00)
currency: null, // use this to pass the currency of the conversion with an ISO 4217 code (e.g. ‘USD’)
contents: [ // use this to pass an array of products or content
// add all items to the array
// use this for the first item
{
content_type: null,
content_id: null,
content_name: null,
content_price: null,
num_items: null,
content_group_id: null
},
// use this for the second item
{
content_type: null,
content_id: null,
content_name: null,
content_price: null,
num_items: null,
content_group_id: null
}],
conversion_id: null, // use this to pass a unique ID for the conversion event for deduplication (e.g. order id '1a2b3c')
email_address: null, // use this to pass a user’s email address
phone_number: null // phone number in E164 standard
});
</script>
<!-- End Twitter conversion tracking event code -->