คุณติดตาม Conversion ทั้งหมดได้โดยการตั้งค่าเหตุการณ์การซื้อในเว็บไซต์ แล้วลิงก์กับ Merchant Center บทความนี้จะอธิบายวิธีตั้งค่าเหตุการณ์การซื้อในเว็บไซต์
ก่อนเริ่มต้น
หากต้องการติดตาม Conversion ให้ตรวจสอบว่าได้เพิ่มแท็ก Google ลงในเว็บไซต์แล้ว หากยังไม่ได้เพิ่ม คุณสามารถสร้างแท็ก Google ใหม่และใช้แท็กนั้นในเว็บไซต์ได้ ดูวิธีติดตั้งแท็ก Google (gtag.js)
วิธีการทำงาน
หากต้องการรวบรวมข้อมูล Conversion คุณต้องติดตามเหตุการณ์การซื้อในเว็บไซต์ ซึ่งทำได้โดยกำหนดเหตุการณ์เหล่านั้นในเว็บไซต์ของคุณ
ด้านล่างนี้คือ 2 ตัวอย่างของวิธีการส่งเหตุการณ์การซื้อจากเว็บไซต์
ตัวอย่างที่ 1: ส่งเหตุการณ์การซื้อเมื่อเปิดหน้าเว็บ
คุณควรวางเหตุการณ์การซื้อไว้ในหน้าเว็บไซต์ที่ผู้ใช้ทำการซื้อ เช่น คุณสามารถเพิ่มเหตุการณ์ลงในหน้ายืนยันที่จะปรากฏเมื่อมีคนทำการซื้อ บทแนะนำนี้จะอธิบายวิธีเพิ่มเหตุการณ์ลงในหน้าเว็บที่มีคนคลิกปุ่ม "ซื้อ"
วางเหตุการณ์ลงในแท็ก <script> ต่อท้ายแท็ก <body> การวางเหตุการณ์ในแท็ก <script> โดยตรงจะทริกเกอร์เหตุการณ์เมื่อโหลดหน้าเว็บ
โค้ดตัวอย่าง
<!--
Note: In the following code sample, make sure to
replace "TAG_ID" with your tag ID.
Learn more: https://support.google.com/tagmanager/answer/12326985
-->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Install the Google tag (gtag.js) -->
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
</head>
<body>
<div> This is where your purchase confirmation would go </div>
<script>
gtag("event", "purchase", {
transaction_id: "T_12345_1",
affiliation: "Google Merchandise Store",
value: 25.42,
tax: 4.90,
shipping: 5.99,
currency: "USD",
coupon: "SUMMER_SALE",
items: [
// If someone purchases more than one item,
// you can add those items to the items array
{
item_id: "SKU_12345",
item_name: "Stan and Friends Tee",
affiliation: "Google Merchandise Store",
coupon: "SUMMER_FUN",
discount: 2.22,
index: 0,
item_brand: "Google",
item_category: "Apparel",
item_category2: "Adult",
item_category3: "Shirts",
item_category4: "Crew",
item_category5: "Short sleeve",
item_list_id: "related_products",
item_list_name: "Related Products",
item_variant: "green",
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
price: 9.99,
quantity: 1
}]
});
</script>
</body>
</html>
ตัวอย่างที่ 2: ส่งเหตุการณ์การซื้อเมื่อมีการคลิกปุ่ม
คุณสามารถตั้งค่าเหตุการณ์การซื้อได้หลายวิธีเพื่อให้ทริกเกอร์เมื่อมีคนคลิกปุ่ม "ซื้อ" วิธีหนึ่งคือการเพิ่มรหัสลงในปุ่ม "ซื้อ" แล้ววางโค้ดเหตุการณ์ใน Listener เหตุการณ์ ในตัวอย่างด้านล่าง ระบบจะส่งเหตุการณ์ก็ต่อเมื่อมีคนคลิกปุ่มซื้อที่มีรหัสเท่านั้น
โค้ดตัวอย่าง
<!--
Note: In the following code sample, make sure to
replace "TAG_ID" with your tag ID.
Learn more: https://support.google.com/tagmanager/answer/12326985
-->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Install the Google tag (gtag.js)-->
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
</head>
<body>
<div>This is where the purchase form would go</div>
<button id="purchase">Purchase</button>
<script>
document.getElementById("purchase").addEventListener("click", function () {
gtag("event", "purchase", {
// This purchase event uses a different transaction ID
// from the previous purchase event so Analytics
// doesn't deduplicate the events.
// Learn more: https://support.google.com/analytics/answer/12313109
transaction_id: "T_12345_2",
affiliation: "Google Merchandise Store",
value: 25.42,
tax: 4.90,
shipping: 5.99,
currency: "USD",
coupon: "SUMMER_SALE",
items: [
{
item_id: "SKU_12345",
item_name: "Stan and Friends Tee",
affiliation: "Google Merchandise Store",
coupon: "SUMMER_FUN",
discount: 2.22,
index: 0,
item_brand: "Google",
item_category: "Apparel",
item_category2: "Adult",
item_category3: "Shirts",
item_category4: "Crew",
item_category5: "Short sleeve",
item_list_id: "related_products",
item_list_name: "Related Products",
item_variant: "green",
location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
price: 9.99,
quantity: 1
}]
});
});
</script>
</body>
</html>
ลิงก์เหตุการณ์การซื้อกับ Merchant Center
คุณสามารถลิงก์เหตุการณ์การซื้อกับ Merchant Center ได้โดยใช้แหล่งที่มาของ Conversion
ดูวิธีเพิ่มแหล่งที่มาของ Conversion ใน Merchant Center