Advertisement
Jawad_Khan

GA4 - Purchase Event

Dec 20th, 2023 (edited)
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <head>
  2.     <!-- Google tag (gtag.js) -->
  3.     <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
  4.     <script>
  5.         window.dataLayer = window.dataLayer || [];
  6.         function gtag(){dataLayer.push(arguments);}
  7.         gtag('js', new Date());
  8.  
  9.         gtag('config', 'TAG_ID');
  10.     </script>
  11. </head>  
  12.  
  13. <body>
  14.     <div>This is where the purchase form would go</div>
  15. <script>
  16.     gtag("event", "purchase", {
  17.         transaction_id: "T_12345_1",
  18.         affiliation: "Google Merchandise Store",
  19.         value: 25.42,
  20.         tax: 4.90,
  21.         shipping: 5.99,
  22.         currency: "USD",
  23.         coupon: "SUMMER_SALE",
  24.         items: [
  25.         // If someone purchases more than one item,
  26.         // you can add those items to the items array
  27.          {
  28.           item_id: "SKU_12345",
  29.           item_name: "Stan and Friends Tee",
  30.           affiliation: "Google Merchandise Store",
  31.           coupon: "SUMMER_FUN",
  32.           discount: 2.22,
  33.           index: 0,
  34.           item_brand: "Google",
  35.           item_category: "Apparel",
  36.           item_category2: "Adult",
  37.           item_category3: "Shirts",
  38.           item_category4: "Crew",
  39.           item_category5: "Short sleeve",
  40.           item_list_id: "related_products",
  41.           item_list_name: "Related Products",
  42.           item_variant: "green",
  43.           location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
  44.           price: 9.99,
  45.           quantity: 1
  46.         }]
  47.     });
  48.     </script>
  49. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement