[GA4] Set up events. Collect additional information from your website or app through events. Google Analytics collects some information by default when you ...
Skiptomaincontent[GA4]SetupeventsCollectadditionalinformationfromyourwebsiteorappthrougheventsGoogleAnalyticscollectssomeinformationbydefaultwhenyousetuptheglobalsitetagortheTagManagersnippetonyourwebsiteortheGoogleAnalyticsforFirebaseSDKinyourapp.Foranyadditionalinformationyouwanttocollect,setuprecommendedorcustomevents.
Thisarticledescribeshowtosetupaneventonyourwebsiteorappsoyoucanaddinformationthat'susefultoyourbusinessinGoogleAnalytics.Ifyouwanttomodifyanexistingevent,seeModifyandcreateeventsviatheuserinterface.
Setupanevent
Whilesettingupcustomevents,notethateventnamesarecase-sensitive;twoeventswhosenamesdifferonlyincasewillresultintwodistinctevents.
Usethefollowingdrop-downstoseeinformationabouthowtosetupanevent:
Globalsitetag(Websites)
Howeventsarestructured
Onceyouaddtheglobalsitetagtoyourwebsite,Googlewillprocessanyeventsyouincludeinyourwebsitecode.Allglobalsitetageventshavethefollowingstructure,whichyoucanlearnmoreaboutintheGlobalsitetagAPIreference:
gtag('event','screen_view',{
});
Aneventincludesthefollowingparts:
isthenameoftherecommendedorcustomevent
isoneormoreparameter-valuepairs,eachseparatedbyacomma
Forexample,thefollowing screen_vieweventincludestwoparameters:
gtag('event','screen_view',{
'app_name':'myAppName',
'screen_name':'Home'
});
Whereyouplacetheeventsonyourwebsite
AllglobalsitetageventsaresentasJavaScript.IfyouhaveastandardHTMLwebsite,youcanaddeventsanywherewithina
Modifywheneventsaresent
BecauseeventsareallwritteninJavaScript,youcanapplyadditionalJavaScripttoyoureventstochangewhenandhowthey'resent.Forexample,ifyouwanttosendaneventwhensomeoneclicksanAddtocartbutton,youcoulddothefollowing:
Step1:AddthebuttonwithanID
Forexample,youcouldaddanaddToCartIDsoyoucansendtheeventwhenthebuttonisclicked.
Addtocart
Step2:Wraptheeventinaneventhandler
Thiscodeidentifiesthebuttonbyitsidandthentriggersthefunctionwhenauserclicksthebutton.Byplacingtheeventinthefunction,theeventonlytriggerswhenthebuttonisclicked.AslongasyouusethesameidforthebuttonandgetElementById()method,youcanusethesestepsforanybuttononyoursite.
document.getElementById("addToCart").addEventListener("click",function(){
gtag("event","add_to_cart",{
currency:"USD",
value:7.77,
items:[
{
item_id:"SKU_12345",
item_name:"StanandFriendsTee",
}
]
});
});
Note:Tomeasurescrollactivitybeyondwhat'sprovidedwithenhancedmeasurement,usethescrolldepthtriggerinGoogleTagManager.Writingacustomscriptusingtheglobalsitetagisnotrecommended.
GoogleTagManager(Websites)
OnceyouaddtheTagManagersnippettoyourwebsiteandcreateaGoogleAnalytics4Configurationtag,createaGoogleAnalytics4Eventtagfortheevent.
TocreateaGoogleAnalytics4Eventtag,followthesesteps:
InGoogleTagManager,clickTags>New.
ClickTagConfiguration>GoogleAnalytics:GA4Event.
InConfigurationTag,selectyourGoogleAnalytics4Configurationtag.
InEventName,enterthenameoftheevent(forexample,view_item_list).
InEventParameters,addarowforeacheventparameter.
Saveandpublishthecontainer.
Whenyouwanttotriggeraneventbasedonacondition(forexample,whensomeoneclicksabutton),createatriggerandthenaddthetriggertotheGoogleAnalytics4Eventtag.
GoogleAnalyticsforFirebase(Mobileapps)
OnceyouinstalltheGoogleAnalyticsforFirebaseSDK,see Logevents intheFirebasedocumentationfordetailsonhowtosetupevents.Youcanalso addTagManagertoyourapp oncetheSDKisinstalledsoyoucanremotelyconfigureeventsandtheirparameterswithinTagManager.
Verifyyourconfigurationinrealtime
Reportsandexplorationscantakeupto24hourstopopulatewithyourecommercedata.Inthemeantime,youcanverifywhetheryou'vesetupyoureventscorrectlybyenablingdebugmode.Onceyouenabledebugmode,youcanusetheDebugViewreporttoseeyourdatainrealtime.
Wasthishelpful?Howcanweimproveit?YesNoSubmitNeedmorehelp?Trythesenextsteps:AsktheHelpCommunityGetanswersfromcommunityexpertstrueEvents[GA4]Events[GA4]Eventparameters[GA4]Automaticallycollectedevents[GA4]Enhancedmeasurementevents[GA4]Recommendedevents[GA4]Customevents[GA4]Setupevents[GA4]Setupecommerceevents[GA4]MonitoreventsinDebugView[GA4]Modifyandcreateeventsviatheuserinterface[GA4]Addcustomparameterstoautomaticallycollectedevents[GA4]Measurepagesandscreens[GA4]Eventcreationvs.audiencetriggers[GA4]EventcollectionlimitsSearchClearsearchClosesearchGoogleappsMainmenuSearchHelpCentertrue69256falsefalse