-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a036105
commit 720b4ac
Showing
6 changed files
with
221 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const rudderanalytics = []; | ||
|
||
rudderanalytics.track("Products Searched", { | ||
query: "HDMI cable", | ||
}); | ||
|
||
rudderanalytics.track("Product List Viewed", { | ||
list_id: "list1", | ||
category: "What's New", | ||
products: [ | ||
{ | ||
product_id: "223344ffdds3ff3", | ||
sku: "12345", | ||
name: "Just Another Game", | ||
price: 22, | ||
position: 2, | ||
category: "Games and Entertainment", | ||
url: "https://www.myecommercewebsite.com/product", | ||
image_url: "https://www.myecommercewebsite.com/product/path.jpg", | ||
}, | ||
{ | ||
product_id: "343344ff5567ff3", | ||
sku: "12346", | ||
name: "Wrestling Trump Cards", | ||
price: 4, | ||
position: 21, | ||
category: "Card Games", | ||
}, | ||
], | ||
}); | ||
|
||
rudderanalytics.track("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", | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const gtag = []; | ||
|
||
gtag("event", "search", { search_term: "HDMI cable" }); | ||
|
||
gtag("event", "view_item_list", { | ||
item_list_id: "list1", | ||
items: [ | ||
{ | ||
item_id: "223344ffdds3ff3", | ||
item_name: "Just Another Game", | ||
price: 22, | ||
index: 2, | ||
item_category: "Games and Entertainment", | ||
item_list_id: "list1", | ||
item_list_name: "What's New", | ||
}, | ||
{ | ||
item_id: "343344ff5567ff3", | ||
item_name: "Wrestling Trump Cards", | ||
price: 4, | ||
index: 21, | ||
item_category: "Card Games", | ||
item_list_id: "list1", | ||
item_list_name: "What's New", | ||
}, | ||
], | ||
item_list_name: "What's New", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,118 @@ | ||
import { | ||
eventNamesConfigArray, | ||
itemParametersConfigArray, | ||
} from "./ECommerceEventConfig"; | ||
|
||
import { pageEventParametersConfigArray } from "./PageEventConfig"; | ||
|
||
function isReservedName(name) { | ||
const reservedEventNames = [ | ||
"ad_activeview", | ||
"ad_click", | ||
"ad_exposure", | ||
"ad_impression", | ||
"ad_query", | ||
"adunit_exposure", | ||
"app_clear_data", | ||
"app_install", | ||
"app_update", | ||
"app_remove", | ||
"error", | ||
"first_open", | ||
"first_visit", | ||
"in_app_purchase", | ||
"notification_dismiss", | ||
"notification_foreground", | ||
"notification_open", | ||
"notification_receive", | ||
"os_update", | ||
"screen_view", | ||
"session_start", | ||
"user_engagement", | ||
]; | ||
|
||
return reservedEventNames.includes(name); | ||
} | ||
|
||
function getDestinationEventName(events) { | ||
return eventNamesConfigArray.find((p) => | ||
p.src.includes(events.toLowerCase()) | ||
); | ||
} | ||
|
||
function getDestinationEventProperties(props, destParameter) { | ||
const destinationProperties = {}; | ||
const item = {}; | ||
Object.keys(props).forEach((key) => { | ||
destParameter.forEach((param) => { | ||
if (key === param.src) { | ||
if (Array.isArray(param.dest)) { | ||
param.dest.forEach((d) => { | ||
const result = d.split("."); | ||
// Here we only support mapping single level object mapping. | ||
// To Do Future Scope :: implement using recursion to handle multi level prop mapping | ||
if (result.length > 1) { | ||
const levelOne = result[0]; | ||
const levelTwo = result[1]; | ||
item[levelTwo] = props[key]; | ||
if (!destinationProperties[levelOne]) { | ||
destinationProperties[levelOne] = []; | ||
destinationProperties[levelOne].push(item); | ||
} | ||
} else { | ||
destinationProperties[result] = props[key]; | ||
eventNamesConfigArray, | ||
itemParametersConfigArray, | ||
} from "./ECommerceEventConfig"; | ||
|
||
import { pageEventParametersConfigArray } from "./PageEventConfig"; | ||
|
||
function isReservedName(name) { | ||
const reservedEventNames = [ | ||
"ad_activeview", | ||
"ad_click", | ||
"ad_exposure", | ||
"ad_impression", | ||
"ad_query", | ||
"adunit_exposure", | ||
"app_clear_data", | ||
"app_install", | ||
"app_update", | ||
"app_remove", | ||
"error", | ||
"first_open", | ||
"first_visit", | ||
"in_app_purchase", | ||
"notification_dismiss", | ||
"notification_foreground", | ||
"notification_open", | ||
"notification_receive", | ||
"os_update", | ||
"screen_view", | ||
"session_start", | ||
"user_engagement", | ||
]; | ||
|
||
return reservedEventNames.includes(name); | ||
} | ||
|
||
function getDestinationEventName(event) { | ||
return eventNamesConfigArray.find((p) => | ||
p.src.includes(event.toLowerCase()) | ||
); | ||
} | ||
|
||
/* | ||
props: {key: val, key2:val2} | ||
destParameter: [{ src: "s", dest: ["d"] }, { src: "sr", dest: ["de", "ef"] }] | ||
output: { | ||
"item_list_id": "list1", | ||
"items": [ | ||
{ | ||
"item_id": "223344ffdds3ff3", | ||
"item_name": "Just Another Game", | ||
}, | ||
{ | ||
"item_id": "343344ff5567ff3", | ||
"item_name": "Wrestling Trump Cards", | ||
"price": 4, | ||
"index": 21, | ||
} | ||
], | ||
"item_list_name": "What's New" | ||
} | ||
*/ | ||
function getDestinationEventProperties(props, destParameterConfig) { | ||
const destinationProperties = {}; | ||
const item = {}; | ||
Object.keys(props).forEach((key) => { | ||
destParameterConfig.forEach((param) => { | ||
if (key === param.src) { | ||
if (Array.isArray(param.dest)) { | ||
param.dest.forEach((d) => { | ||
const result = d.split("."); | ||
// Here we only support mapping single level object mapping. | ||
// To Do Future Scope :: implement using recursion to handle multi level prop mapping | ||
if (result.length > 1) { | ||
const levelOne = result[0]; | ||
const levelTwo = result[1]; | ||
item[levelTwo] = props[key]; | ||
if (!destinationProperties[levelOne]) { | ||
destinationProperties[levelOne] = []; | ||
destinationProperties[levelOne].push(item); | ||
} | ||
}); | ||
} else { | ||
destinationProperties[param.dest] = props[key]; | ||
} | ||
} else { | ||
destinationProperties[result] = props[key]; | ||
} | ||
}); | ||
} else { | ||
destinationProperties[param.dest] = props[key]; | ||
} | ||
}); | ||
} | ||
}); | ||
return destinationProperties; | ||
} | ||
function getDestinationItemProperties(products, item) { | ||
const items = []; | ||
let obj = {}; | ||
products.forEach((p) => { | ||
obj = { | ||
...getDestinationEventProperties(p, itemParametersConfigArray), | ||
...(item && item[0]), | ||
}; | ||
items.push(obj); | ||
}); | ||
return items; | ||
} | ||
function getPageViewProperty(props) { | ||
return getDestinationEventProperties(props, pageEventParametersConfigArray); | ||
} | ||
export { | ||
isReservedName, | ||
getDestinationEventName, | ||
getDestinationEventProperties, | ||
getDestinationItemProperties, | ||
getPageViewProperty, | ||
}; | ||
}); | ||
return destinationProperties; | ||
} | ||
|
||
function getDestinationItemProperties(products, item) { | ||
const items = []; | ||
let obj = {}; | ||
products.forEach((p) => { | ||
obj = { | ||
...getDestinationEventProperties(p, itemParametersConfigArray), | ||
...(item && item[0]), | ||
}; | ||
items.push(obj); | ||
}); | ||
return items; | ||
} | ||
|
||
function getPageViewProperty(props) { | ||
return getDestinationEventProperties(props, pageEventParametersConfigArray); | ||
} | ||
|
||
export { | ||
isReservedName, | ||
getDestinationEventName, | ||
getDestinationEventProperties, | ||
getDestinationItemProperties, | ||
getPageViewProperty, | ||
}; |
Oops, something went wrong.