הגדרת אירוע רכישה

במדריך הזה מוסבר איך להגדיר אירוע purchase באתר כדי למדוד מתי משתמשים מבצעים רכישה. המדריך כולל את המאפיינים, המדדים והדוחות שמערכת Analytics מאכלסת בנתונים מהאירוע. מידע נוסף על אירועי מסחר אלקטרוני זמין במאמר מדידת מסחר אלקטרוני.

לפני שמתחילים

המדריך הזה מתבסס על ההנחה שביצעתם את הפעולות הבאות:

בנוסף, אנחנו יוצאים מנקודת הנחה שיש לכם:

  • גישה לקוד המקור של האתר
  • הרשאת עריכה (או הרשאה גבוהה יותר) בחשבון Google Analytics

שלב 1: מוסיפים את האירוע לאתר

כדאי להציב את האירוע purchase בדף באתר שבו מישהו מבצע רכישה. לדוגמה, אפשר להוסיף את האירוע לדף האישור שמופיע אחרי שאנשים מבצעים רכישה. המדריך הזה מסביר איך להוסיף את האירוע לדף שבו אנשים לוחצים על לחצן לביצוע רכישה.

מציבים את האירוע בתג <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>
    <!-- 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>Submit</button>
    <script>
    gtag("event", "purchase", {
        transaction_id: "T_12345_1",
        value: 30.03,
        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: 10.01,
          quantity: 3
        }]
    });
    </script>
</body>
</html>

שלב 2: מחברים את האירוע ללחצן

יש כמה דרכים שבהן אפשר להגדיר את האירוע purchase כך שיופעל כשמישהו ילחץ על לחצן לביצוע רכישה. אחת הדרכים היא להוסיף מזהה ללחצן לביצוע הרכישה ואחר כך להציב את קוד האירוע בתוך event listener. בדוגמה הבאה, האירוע נשלח רק כאשר לוחצים על לחצן עם המזהה purchase.

<!--
  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>
    <!-- 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",
                value: 30.03,
                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: 10.01,
                  quantity: 3
                }]
          });
      });
    </script>
</body>
</html>

שלב 3: מוודאים שאתם אוספים את הנתונים

הדוח DebugView מציג נתונים בזמן אמת מהאתר שלכם, כדי לוודא שהגדרתם את האירועים בצורה נכונה. כדי להפעיל את מצב ניפוי הבאגים בדף אינטרנט, צריך להוסיף את הפרמטר debug_mode הבא לפקודה config:

<!--
  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>
    <!-- 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',{ 'debug_mode': true });
    </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_3",
                value: 30.03,
                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: 10.01,
                  quantity: 3
                }]
        });
    });
    </script>
</body>
</html>

אחרי שתפעילו את מצב ניפוי הבאגים, תתחילו לראות אירועים מאכלסים את הדוח DebugView בזמן שאנשים משתמשים באתר. לדוגמה, לחיצה על הלחצן "רכישה" באתר מאכלסת את הדוח בנתונים הבאים. אפשר לבחור אירוע כדי לראות את הפרמטרים, מאפייני המשתמשים והפריטים שמשויכים לאירוע.

צילום מסך של הדוח DebugView

שלב 4: הצגה של נתוני המסחר האלקטרוני

אחרי כ-24 שעות, הנתונים ששלחתם עם האירוע purchase הופכים לזמינים בדוחות, בכלי הניתוחים וב-Google Analytics Data API. אפשר לגשת לנתונים ב-BigQuery גם כשמגדירים את BigQuery Export.

האירוע purchase (רכישה) מאכלס באופן אוטומטי מגוון מאפיינים ומדדים מוכנים מראש, שאפשר להשתמש בהם בדוחות, בניתוחים וכו'. ריכזנו כאן כמה מהמאפיינים שמאוכלסים בנתונים מהאירוע purchase בשלב הראשון:

פרמטר המאפיין ערך
affiliation שיוך הפריט Google Merchandise Store [חנות המרצ'נדייז של Google]
currency מטבע USD
discount סכום ההנחה של פריט 2.22
index המיקום של רשימת הפריטים 0
item_brand המותג של הפריט Google
item_category קטגוריית הפריט ביגוד
item_id מזהה פריט SKU_12345
item_list_id מזהה רשימת הפריטים related_products
item_list_name השם של רשימת הפריטים מוצרים קשורים
item_name שם הפריט חולצת Stan and Friends
item_variant וריאציית הפריט green
location_id מזהה המיקום של הפריט ChIJIQBpAG2ahYAR_6128GcTUEo (מזהה מקום Google של סן פרנסיסקו)
shipping סכום המשלוח 5.99
tax סכום המס 4.90
transaction_id מזהה עסקה T_12345

בנוסף למאפיינים, Google Analytics מאכלס מספר מדדים הקשורים למסחר אלקטרוני ולהכנסות. לדוגמה, אם משתמש ילחץ פעם אחת על הלחצן 'רכישה', המדדים הבאים יאוכלסו ב-Google Analytics:

  • למדד הכנסה מפריט יש ערך של 30.03$
  • למדד סה"כ הכנסות יש ערך של 30.03$
  • הערך רכישות במסחר אלקטרוני הוא 1

אפשר להשתמש במאפיינים ובמדדים האלה כדי ליצור ניתוחים ודוחות בהתאמה אישית, אבל אפשר גם להשתמש בדוח רכישות במסחר אלקטרוני שנבנה מראש כדי לראות את נתוני המסחר האלקטרוני:

צילום מסך של הדוח &#39;רכישות במסחר אלקטרוני&#39;