Skip to content

Commit

Permalink
updated logic, eventConfig and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivam4415 committed Dec 18, 2020
1 parent 366d838 commit 5ee6d8c
Show file tree
Hide file tree
Showing 9 changed files with 1,096 additions and 670 deletions.
117 changes: 117 additions & 0 deletions __tests__/data/GA4_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,120 @@ rudderanalytics.track("Product List Filtered", {
},
],
});

rudderanalytics.track("Product Clicked", {
product_id: "123",
sku: "F15",
category: "Games",
name: "Game",
brand: "Gamepro",
variant: "111",
price: 13.49,
quantity: 11,
coupon: "DISC21",
position: 1,
url: "https://www.website.com/product/path",
image_url: "https://www.website.com/product/path.png",
});

rudderanalytics.track("Product Viewed", {
product_id: "123",
sku: "F15",
category: "Games",
name: "Game",
brand: "Gamepro",
variant: "111",
price: 13.49,
quantity: 11,
coupon: "DISC21",
currency: "USD",
position: 1,
url: "https://www.website.com/product/path",
image_url: "https://www.website.com/product/path.png",
});

rudderanalytics.track("Product Added", {
product_id: "123",
sku: "F15",
category: "Games",
name: "Game",
brand: "Gamepro",
variant: "111",
price: 13.49,
quantity: 11,
coupon: "DISC21",
position: 1,
url: "https://www.website.com/product/path",
image_url: "https://www.website.com/product/path.png",
});

rudderanalytics.track("Product Removed", {
product_id: "123",
sku: "F15",
category: "Games",
name: "Game",
brand: "Gamepro",
variant: "111",
price: 13.49,
quantity: 11,
coupon: "DISC21",
position: 1,
url: "https://www.website.com/product/path",
image_url: "https://www.website.com/product/path.png",
});

rudderanalytics.track("Cart Viewed", {
cart_id: "12345",
products: [
{
product_id: "123",
sku: "G-14",
name: "Cards",
price: 14.99,
position: 1,
category: "Games",
url: "https://www.website.com/product/path",
image_url: "https://www.website.com/product/path.jpg",
},
{
product_id: "345",
sku: "G-32",
name: "UNO",
price: 3.99,
position: 2,
category: "Games",
},
],
});

rudderanalytics.track("Checkout Started", {
order_id: "1234",
affiliation: "Apple Store",
value: 20,
revenue: 15.0,
shipping: 22,
tax: 1,
discount: 1.5,
coupon: "ImagePro",
currency: "USD",
products: [
{
product_id: "123",
sku: "G-32",
name: "Monopoly",
price: 14,
quantity: 1,
category: "Games",
url: "https://www.website.com/product/path",
image_url: "https://www.website.com/product/path.jpg",
},
{
product_id: "345",
sku: "F-32",
name: "UNO",
price: 3.45,
quantity: 2,
category: "Games",
},
],
});
153 changes: 153 additions & 0 deletions __tests__/data/GA4_output.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,156 @@ gtag("event", "view_item_list", {
],
item_list_name: "What's New",
});

gtag("event", "Product List Filtered", {
list_id: "dealoftheday",
filters: [
{
type: "department",
value: "health",
},
{
type: "price",
value: "under-$75",
},
],
sorts: [
{
type: "price",
value: "asc",
},
],
products: [
{
product_id: "5034221345ffcd672315011",
sku: "12345",
name: "Whey Protein",
price: 55.45,
position: 1,
category: "health",
url: "https://www.myecommercewebsite.com/product/product1123",
image_url: "https://www.example.com/product/1123.jpg",
},
{
product_id: "121244455323232326677232",
sku: "345667",
name: "Boost",
price: 47.85,
position: 12,
category: "health",
},
],
});

gtag("event", "select_item", {
items: [
{
item_id: "123",
item_category: "Games",
item_name: "Game",
item_brand: "Gamepro",
item_variant: "111",
price: 13.49,
quantity: 11,
coupon: "DISC21",
index: 1,
},
],
});

gtag("event", "view_item", {
items: [
{
item_id: "123",
item_category: "Games",
item_name: "Game",
item_brand: "Gamepro",
item_variant: "111",
price: 13.49,
quantity: 11,
coupon: "DISC21",
index: 1,
},
],
});

window.gtag("event", "add_to_cart", {
items: [
{
item_id: "123",
item_category: "Games",
item_name: "Game",
item_brand: "Gamepro",
item_variant: "111",
price: 13.49,
quantity: 11,
coupon: "DISC21",
index: 1,
},
],
});

window.gtag("event", "remove_from_cart", {
items: [
{
item_id: "123",
item_category: "Games",
item_name: "Game",
item_brand: "Gamepro",
item_variant: "111",
price: 13.49,
quantity: 11,
coupon: "DISC21",
index: 1,
},
],
});

window.gtag("event", "view_cart", {
items: [
{
item_id: "123",
item_name: "Cards",
price: 14.99,
index: 1,
item_category: "Games",
},
{
item_id: "345",
item_name: "UNO",
price: 3.99,
index: 2,
item_category: "Games",
},
],
});

window.gtag("event", "begin_checkout", {
affiliation: "Apple Store",
shipping: 22,
tax: 1,
coupon: "ImagePro",
currency: "USD",
items: [
{
item_id: "123",
item_name: "Monopoly",
price: 14,
quantity: 1,
item_category: "Games",
affiliation: "Apple Store",
coupon: "ImagePro",
currency: "USD",
},
{
item_id: "345",
item_name: "UNO",
price: 3.45,
quantity: 2,
item_category: "Games",
affiliation: "Apple Store",
coupon: "ImagePro",
currency: "USD",
},
],
});
Loading

0 comments on commit 5ee6d8c

Please sign in to comment.