يمكنك تتبُّع كل عمليات الشراء من خلال إعداد أحداث الشراء على موقعك الإلكتروني وربطها بحسابك على Merchant Center. توضّح هذه المقالة كيفية إعداد أحداث الشراء على موقعك الإلكتروني.
قبل البدء
لتتبُّع عمليات الشراء، تأكَّد من إضافة علامة تتبُّع من Google إلى موقعك الإلكتروني. وإذا لم يسبق لك إضافة علامة، يمكنك إنشاء واحدة جديدة واستخدامها على موقعك الإلكتروني. تعرَّف على كيفية تثبيت علامة Google (gtag.js).
آلية العمل
لجمع بيانات عمليات الشراء، عليك تتبُّع أحداث الشراء على موقعك الإلكتروني. ولتتبُّع هذه الأحداث، يجب تحديدها على موقعك الإلكتروني.
في ما يلي مثالان على كيفية إرسال حدث شراء من موقعك الإلكتروني.
المثال 1: إرسال حدث الشراء عند فتح الصفحة
يجب تحديد موضع حدث الشراء على الصفحة التي يُجري فيها المستخدمون عملية الشراء على موقعك الإلكتروني. على سبيل المثال، يمكنك إضافة الحدث إلى صفحة التأكيد التي تظهر عند إجراء عملية شراء. يوضّح لك هذا الدليل التوجيهي كيفية إضافة الحدث إلى صفحة تتضمّن الزر "شراء".
أضِف الحدث في علامة <script> في نهاية علامة <body>. عند إضافة الحدث في علامة <script> مباشرةً، يتم تشغيله عند تحميل الصفحة.
رمز نموذجي
<!--
ملاحظة: في الرمز النموذجي التالي، تأكَّد من
استبدال 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: إرسال حدث الشراء عند النقر على زر
يمكنك إعداد حدث الشراء بعدة طرق بحيث يتم تشغيله عند النقر على الزر "شراء". بإمكانك مثلاً إضافة معرّف إلى الزر "شراء" ثم وضع رمز الحدث في أداة معالجة الحدث. في المثال أدناه، لا يتم إرسال الحدث إلا عندما ينقر مستخدم على زر أُضيف له معرّف العلامة "شراء".
رمز نموذجي
<!--
ملاحظة: في الرمز البرمجي التالي، تأكَّد من
استبدال 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.
// مزيد من المعلومات: 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 باستخدام مصادر الأحداث الرئيسية.
التعرّف على كيفية إضافة مصادر الأحداث الرئيسية في Merchant Center