feat: add events

This commit is contained in:
Kevin Franklin Kim 2024-05-15 13:17:45 +02:00
parent ce5bd23d48
commit 453e5159a1
No known key found for this signature in database
37 changed files with 331 additions and 66 deletions

View File

@ -6,6 +6,10 @@
> **Se**rver **S**ide T**a**g **M**anagement **S**ystem
## References
- [Event naming rules](https://support.google.com/analytics/answer/13316687)
## How to Contribute
Make a pull request...

12
event/click.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type Click sesamy.Event[params.Click]
func NewClick(p params.Click) Click {
return Click(sesamy.NewEvent(sesamy.EventNameClick, p))
}

12
event/filedownload.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type FileDownload sesamy.Event[params.FileDownload]
func NewFileDownload(p params.FileDownload) FileDownload {
return FileDownload(sesamy.NewEvent(sesamy.EventNameFileDownload, p))
}

12
event/formstart.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type FormStart sesamy.Event[params.FormStart]
func NewFormStart(p params.FormStart) FormStart {
return FormStart(sesamy.NewEvent(sesamy.EventNameFormStart, p))
}

12
event/formsubmit.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type FormSubmit sesamy.Event[params.FormSubmit]
func NewFormSubmit(p params.FormSubmit) FormSubmit {
return FormSubmit(sesamy.NewEvent(sesamy.EventNameFormSubmit, p))
}

View File

@ -1,10 +1,14 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// AddPaymentInfo https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events
type AddPaymentInfo[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Coupon string `json:"coupon,omitempty"`
PaymentType string `json:"payment_type,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Coupon string `json:"coupon,omitempty"`
PaymentType string `json:"payment_type,omitempty"`
Items []Item `json:"items,omitempty"`
}

View File

@ -1,10 +1,14 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// AddShippingInfo https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#add_shipping_info
type AddShippingInfo[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Coupon string `json:"coupon,omitempty"`
ShippingTier string `json:"shipping_tier,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Coupon string `json:"coupon,omitempty"`
ShippingTier string `json:"shipping_tier,omitempty"`
Items []Item `json:"items,omitempty"`
}

View File

@ -1,8 +1,12 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// AddToCart https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#add_to_cart
type AddToCart[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
}

View File

@ -1,8 +1,12 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// AddToWishlist https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#add_to_wishlist
type AddToWishlist[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
}

View File

@ -1,10 +1,15 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// AdImpression https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#ad_impression
type AdImpression struct {
AdPlatform string `json:"ad_platform,omitempty" mapstructure:"ad_platform"`
AdSource string `json:"ad_source,omitempty" mapstructure:"ad_source"`
AdFormat string `json:"ad_format,omitempty" mapstructure:"ad_format"`
AdUnitName string `json:"ad_unit_name,omitempty" mapstructure:"ad_unit_name"`
Currency string `json:"currency,omitempty" mapstructure:"currency"`
AdPlatform string `json:"ad_platform,omitempty"`
AdSource string `json:"ad_source,omitempty"`
AdFormat string `json:"ad_format,omitempty"`
AdUnitName string `json:"ad_unit_name,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
}

View File

@ -1,9 +1,13 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// BeginCheckout https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#begin_checkout
type BeginCheckout[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Coupon string `json:"coupon,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Coupon string `json:"coupon,omitempty"`
Items []Item `json:"items,omitempty"`
}

9
event/params/click.go Normal file
View File

@ -0,0 +1,9 @@
package params
type Click struct {
LinkClasses string `json:"link_classes,omitempty"`
LinkDomain string `json:"link_domain,omitempty"`
LinkID string `json:"link_id,omitempty"`
LinkURL string `json:"link_url,omitempty"`
Outbound bool `json:"outbound,omitempty"`
}

View File

@ -0,0 +1,10 @@
package params
type FileDownload struct {
FileExtension string `json:"file_extension,omitempty"`
FileName string `json:"file_name,omitempty"`
LinkClasses string `json:"link_classes,omitempty"`
LinkID string `json:"link_id,omitempty"`
LinkText string `json:"link_text,omitempty"`
LinkURL string `json:"link_url,omitempty"`
}

View File

@ -0,0 +1,7 @@
package params
type FormStart struct {
FormID string `json:"form_id,omitempty"`
FormName string `json:"form_name,omitempty"`
FormDestination string `json:"form_destination,omitempty"`
}

View File

@ -0,0 +1,8 @@
package params
type FormSubmit struct {
FormID string `json:"form_id,omitempty"`
FormName string `json:"form_name,omitempty"`
FormDestination string `json:"form_destination,omitempty"`
FormSubmitText string `json:"form_submit_text,omitempty"`
}

View File

@ -1,7 +1,11 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// GenerateLead https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#generate_lead
type GenerateLead struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
}

View File

@ -1,12 +1,16 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// Purchase https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#purchase
type Purchase[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
TransactionID string `json:"transaction_id,omitempty"`
Coupon string `json:"coupon,omitempty"`
Shipping float64 `json:"shipping,omitempty"`
Tax float64 `json:"tax,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
TransactionID string `json:"transaction_id,omitempty"`
Coupon string `json:"coupon,omitempty"`
Shipping float64 `json:"shipping,omitempty"`
Tax float64 `json:"tax,omitempty"`
Items []Item `json:"items,omitempty"`
}

View File

@ -1,12 +1,16 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// Refund https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#refund
type Refund[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
TransactionID string `json:"transaction_id,omitempty"`
Coupon string `json:"coupon,omitempty"`
Shipping float64 `json:"shipping,omitempty"`
Tax float64 `json:"tax,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
TransactionID string `json:"transaction_id,omitempty"`
Coupon string `json:"coupon,omitempty"`
Shipping float64 `json:"shipping,omitempty"`
Tax float64 `json:"tax,omitempty"`
Items []Item `json:"items,omitempty"`
}

View File

@ -1,8 +1,12 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// RemoveFromCart https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#remove_from_cart
type RemoveFromCart[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
}

5
event/params/scroll.go Normal file
View File

@ -0,0 +1,5 @@
package params
type Scroll struct {
EngagementTimeMsec int64 `json:"engagement_time_msec,omitempty"`
}

View File

@ -0,0 +1,3 @@
package params
type SessionStart struct{}

View File

@ -1,6 +1,6 @@
package params
// UnlockArchievement https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#unlock_achievement
type UnlockArchievement struct {
ArchievementName string `json:"archievement_name"`
// UnlockAchievement https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#unlock_achievement
type UnlockAchievement struct {
ArchievementID string `json:"achievement_id"`
}

View File

@ -0,0 +1,5 @@
package params
type UserEngagement struct {
EngagementTimeMsec int64 `json:"engagement_time_msec,omitempty"`
}

View File

@ -0,0 +1,11 @@
package params
type VideoComplete struct {
VideoCurrentTime int64 `json:"video_current_time,omitempty"`
VideoDuration int64 `json:"video_duration,omitempty"`
VideoPercent int64 `json:"video_percent,omitempty"`
VideoProvider string `json:"video_provider,omitempty"`
VideoTitle string `json:"video_title,omitempty"`
VideoURL string `json:"video_url,omitempty"`
Visible bool `json:"visible,omitempty"`
}

View File

@ -0,0 +1,11 @@
package params
type VideoProgress struct {
VideoCurrentTime int64 `json:"video_current_time,omitempty"`
VideoDuration int64 `json:"video_duration,omitempty"`
VideoPercent int64 `json:"video_percent,omitempty"`
VideoProvider string `json:"video_provider,omitempty"`
VideoTitle string `json:"video_title,omitempty"`
VideoURL string `json:"video_url,omitempty"`
Visible bool `json:"visible,omitempty"`
}

View File

@ -0,0 +1,11 @@
package params
type VideoStart struct {
VideoCurrentTime int64 `json:"video_current_time,omitempty"`
VideoDuration int64 `json:"video_duration,omitempty"`
VideoPercent int64 `json:"video_percent,omitempty"`
VideoProvider string `json:"video_provider,omitempty"`
VideoTitle string `json:"video_title,omitempty"`
VideoURL string `json:"video_url,omitempty"`
Visible bool `json:"visible,omitempty"`
}

View File

@ -1,8 +1,12 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// ViewCart https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#view_cart
type ViewCart[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
}

View File

@ -1,8 +1,12 @@
package params
import (
"github.com/foomo/gostandards/iso4217"
)
// ViewItem https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#view_item
type ViewItem[Item any] struct {
Currency string `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
Currency iso4217.Currency `json:"currency,omitempty"`
Value float64 `json:"value,omitempty"`
Items []Item `json:"items,omitempty"`
}

12
event/scroll.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type Scroll sesamy.Event[params.Scroll]
func NewScroll(p params.Scroll) Scroll {
return Scroll(sesamy.NewEvent(sesamy.EventNameScroll, p))
}

12
event/sessionstart.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type SessionStart sesamy.Event[params.SessionStart]
func NewSessionStart(p params.SessionStart) SessionStart {
return SessionStart(sesamy.NewEvent(sesamy.EventNameSessionStart, p))
}

View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type UnlockAchievement sesamy.Event[params.UnlockAchievement]
func NewUnlockArchievement(p params.UnlockAchievement) UnlockAchievement {
return UnlockAchievement(sesamy.NewEvent(sesamy.EventNameUnlockArchievement, p))
}

View File

@ -1,12 +0,0 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type UnlockArchievement sesamy.Event[params.UnlockArchievement]
func NewUnlockArchievement(p params.UnlockArchievement) UnlockArchievement {
return UnlockArchievement(sesamy.NewEvent(sesamy.EventNameUnlockArchievement, p))
}

12
event/userengagement.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type UserEngagement sesamy.Event[params.UserEngagement]
func NewUserEngagement(p params.UserEngagement) UserEngagement {
return UserEngagement(sesamy.NewEvent(sesamy.EventNameUserEngagement, p))
}

12
event/videocomplete.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type VideoComplete sesamy.Event[params.VideoComplete]
func NewVideoComplete(p params.VideoComplete) VideoComplete {
return VideoComplete(sesamy.NewEvent(sesamy.EventNameVideoComplete, p))
}

12
event/videoprogress.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type VideoProgress sesamy.Event[params.VideoProgress]
func NewVideoProgress(p params.VideoProgress) VideoProgress {
return VideoProgress(sesamy.NewEvent(sesamy.EventNameVideoProgress, p))
}

12
event/videostart.go Normal file
View File

@ -0,0 +1,12 @@
package event
import (
"github.com/foomo/sesamy-go"
"github.com/foomo/sesamy-go/event/params"
)
type VideoStart sesamy.Event[params.VideoStart]
func NewVideoStart(p params.VideoStart) VideoStart {
return VideoStart(sesamy.NewEvent(sesamy.EventNameVideoStart, p))
}

View File

@ -2,16 +2,23 @@ package sesamy
type EventName string
// List of standard events
// - [[GA4] Automatically collected events](https://support.google.com/analytics/answer/9234069
// - [[GA4] Enhanced measurement events](https://support.google.com/analytics/answer/9216061)
// - [[GA4] Recommended events](https://support.google.com/analytics/answer/9267735)
const (
EventNameAdImpression EventName = "ad_impression"
EventNameAddPaymentInfo EventName = "add_payment_info"
EventNameAddShippingInfo EventName = "add_shipping_info"
EventNameAddToCart EventName = "add_to_cart"
EventNameAddToWishlist EventName = "add_to_wishlit"
EventNameAdImpression EventName = "ad_impression"
EventNameBeginCheckout EventName = "begin_checkout"
EventNameCampaignDetails EventName = "campaign_details"
EventNameClick EventName = "click"
EventNameEarnVirtualMoney EventName = "earn_virtual_money"
EventNameFileDownload EventName = "file_download"
EventNameFormStart EventName = "form_start"
EventNameFormSubmit EventName = "form_submit"
EventNameGenerateLead EventName = "generate_lead"
EventNameJoinGroup EventName = "join_group"
EventNameLevelEnd EventName = "level_end"
@ -29,12 +36,17 @@ const (
EventNameSelectContent EventName = "select_content"
EventNameSelectItem EventName = "select_item"
EventNameSelectPromotion EventName = "select_promotion"
EventNameSessionStart EventName = "session_start"
EventNameShare EventName = "share"
EventNameSignUp EventName = "sign_up"
EventNameSpendVirtualCurrency EventName = "spend_virtual_currency"
EventNameTutorialBegin EventName = "tutorial_begin"
EventNameTutorialComplete EventName = "tutorial_complete"
EventNameUnlockArchievement EventName = "unlock_archievement"
EventNameUserEngagement EventName = "user_engagement"
EventNameVideoComplete EventName = "video_complete"
EventNameVideoProgress EventName = "video_progress"
EventNameVideoStart EventName = "video_start"
EventNameViewCart EventName = "view_cart"
EventNameViewItem EventName = "view_item"
EventNameViewItemList EventName = "view_item_list"