Skip to content

Commit

Permalink
Add screen_view, ad_impression, campaign_details events to EventBuild…
Browse files Browse the repository at this point in the history
…er (#1861)
  • Loading branch information
ikuleshov authored Apr 25, 2024
1 parent 598a24f commit 67777f8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Event and required property mapping

export const eventDefinitions = {
"ad_impression": [],
"add_payment_info": ["value", "items"],
"add_shipping_info": ["value", "items"],
"add_to_cart": ["value", "items"],
"add_to_wishlist": ["value", "items"],
"begin_checkout": ["value", "items"],
"campaign_details": [],
"earn_virtual_currency": [],
"generate_lead": ["value"],
"join_group": [],
Expand All @@ -15,6 +17,7 @@ export const eventDefinitions = {
"purchase": ["transaction_id", "items", "value"],
"refund": ["transaction_id", "value"],
"remove_from_cart": ["items", "value"],
"screen_view": [],
"search": ["search_term"],
"select_content": [],
"select_item": ["items"],
Expand Down
41 changes: 41 additions & 0 deletions src/components/ga4/EventBuilder/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ const eventFor = (

const custom_event = eventFor(EventType.CustomEvent, [Category.Custom], [], [])

const ad_impression = eventFor(
EventType.AdImpression,
[Category.AllApps],
[
stringParam("ad_platform", "MoPub"),
stringParam("ad_source", "AdColony"),
stringParam("ad_format", "Banner"),
stringParam("ad_unit_name", "Banner_03"),
stringParam("currency", "USD"),
numberParam("value", 3.99),
]
)

const add_payment_info = eventFor(
EventType.AddPaymentInfo,
[Category.RetailEcommerce],
Expand Down Expand Up @@ -159,6 +172,19 @@ const begin_checkout = eventFor(
]
)

const campaign_details = eventFor(
EventType.CampaignDetails,
[Category.AllApps],
[
stringParam("campaign_id", "SUMMER_FUN"),
stringParam("campaign", "Summer_fun"),
stringParam("source", "google"),
stringParam("medium", "cpc"),
stringParam("term", "summer+travel"),
stringParam("content", "logolink"),
]
)

const earn_virtual_currency = eventFor(
EventType.EarnVirtualCurrency,
[Category.AllApps],
Expand Down Expand Up @@ -274,6 +300,15 @@ const remove_from_cart = eventFor(
]
)

const screen_view = eventFor(
EventType.ScreenView,
[Category.AllApps],
[
stringParam("screen_class", "MainActivity"),
stringParam("screen_name", "About"),
]
)

const search = eventFor(
EventType.Search,
[Category.AllApps],
Expand Down Expand Up @@ -489,6 +524,8 @@ export const suggestedEventFor = (eventType: EventType): Event2 => {
case EventType.CustomEvent:
return custom_event

case EventType.AdImpression:
return ad_impression
case EventType.AddPaymentInfo:
return add_payment_info
case EventType.AddShippingInfo:
Expand All @@ -499,6 +536,8 @@ export const suggestedEventFor = (eventType: EventType): Event2 => {
return add_to_wishlist
case EventType.BeginCheckout:
return begin_checkout
case EventType.CampaignDetails:
return campaign_details
case EventType.EarnVirtualCurrency:
return earn_virtual_currency
case EventType.GenerateLead:
Expand All @@ -517,6 +556,8 @@ export const suggestedEventFor = (eventType: EventType): Event2 => {
return refund
case EventType.RemoveFromCart:
return remove_from_cart
case EventType.ScreenView:
return screen_view
case EventType.Search:
return search
case EventType.SelectContent:
Expand Down
4 changes: 3 additions & 1 deletion src/components/ga4/EventBuilder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ export enum Category {

export enum EventType {
CustomEvent = "custom_event",

AdImpression = "ad_impression",
AddPaymentInfo = "add_payment_info",
AddShippingInfo = "add_shipping_info",
AddToCart = "add_to_cart",
AddToWishlist = "add_to_wishlist",
BeginCheckout = "begin_checkout",
CampaignDetails = "campaign_details",
EarnVirtualCurrency = "earn_virtual_currency",
GenerateLead = "generate_lead",
JoinGroup = "join_group",
Expand All @@ -43,6 +44,7 @@ export enum EventType {
Purchase = "purchase",
Refund = "refund",
RemoveFromCart = "remove_from_cart",
ScreenView = "screen_view",
Search = "search",
SelectContent = "select_content",
SelectItem = "select_item",
Expand Down

0 comments on commit 67777f8

Please sign in to comment.