Measurement Protocol Reference - Google Developers
文章推薦指數: 80 %
https://www.google-analytics.com/collect. All data should be sent securely with the HTTPS protocol. You can send data using either POST or GET requests. Google Analytics Measurement MeasurementProtocol(UniversalAnalytics) Language English BahasaIndonesia Deutsch Español Français Português–Brasil Русский 中文–简体 日本語 한국어 Signin Guides Reference Support Google Analytics Measurement MeasurementProtocol(UniversalAnalytics) Guides Reference Support ProtocolReference ParameterReference GeographicalIDs ThisdocumentationisforUniversalAnalytics.SeeMeasurementProtocol(GoogleAnalytics4)ifyouareusingGoogleAnalytics4. Home Products GoogleAnalytics Measurement MeasurementProtocol(UniversalAnalytics) Reference MeasurementProtocolReference ThisdocumentdescribeshowtosenddatatoGoogleAnalyticsusingtheMeasurementProtocol. Overview Thereare2partstosenddatatoGoogleAnalyticsusingtheMeasurementProtocol: Thetransport–towhereandhowyousenddata Thepayload–thedatayousend Thisdocumentdescribeshowtoformatboth. Transport URLEndpoint YousenddatausingtheMeasurementProtocolbymakingHTTPrequeststothe followingendpoint: https://www.google-analytics.com/collect AlldatashouldbesentsecurelywiththeHTTPSprotocol. YoucansenddatausingeitherPOSTorGET requests. UsingPOST WerecommendsendingdataviaPOSTbecauseitallowsfor alargerpayload.WhenusingPOST,issuethefollowingHTTPrequest: User-Agent:user_agent_string POSThttps://www.google-analytics.com/collect payload_data Where: user_agent_string–Isa formatteduseragentstringthatisusedtocomputethe followingdimensions:browser,platform,andmobilecapabilities. Ifthisvalueisnotset,thedataabovewillnotbecomputed. payload_data–TheBODYof thepostrequest.Thebodymustincludeexactly1URIencoded payloadandmustbenolongerthan8192bytes. IPAddress–IsimplicitlysentintheHTTP requestandisusedtocomputeallthegeo/networkdimensions inGoogleAnalytics. GET ForenvironmentswhereyoucannotsendPOSTdata,youcanalsosend HTTPGETrequeststothesameendpoint: GET/collect?payload_dataHTTP/1.1 Host:https://www.google-analytics.com User-Agent:user_agent_string WherethepayloaddataissentasURIescapedqueryparameters. ThelengthoftheentireencodedURLmustbenolongerthan8000Bytes. CacheBusting Insomeenvironments,likebrowsers,HTTPGETrequestsmightgetcached. Whenarequestgetscached,subsequentrequestsmightberetrievedfromthe cache,andnotsenttoGoogleAnalytics.Tobustthroughthecache, theMeasurementProtocolprovidesaspecialparameter (z)thatcanbesetwitharandomnumber.Thisensuresall MeasurementProtocolrequestsareunique,andthatsubsequentrequestsarenot retrievedfromthecache. Whenyouusethecachebuster,wehighlyrecommendaddingthisparameteras thelastparameterinthepayload. https://www.google-analytics.com/collect?payload_data&z=123456 ResponseCodes TheMeasurementProtocolwillreturna2xxstatuscodeiftheHTTP requestwasreceived.TheMeasurementProtocoldoesnotreturnanerrorcodeif thepayloaddatawasmalformed,orifthedatainthepayloadwasincorrect orwasnotprocessedbyGoogleAnalytics. Ifyoudonotgeta2xxstatuscode,youshould NOTretrytherequest.Instead,youshouldstopandcorrect anyerrorsinyourHTTPrequest. PayloadData AlldatacollectedbyGoogleAnalyticsusingtheMeasurementProtocolissentas apayload.ThepayloadresemblesaURLquerystringwhereeach parameterhasakeyandvalue,isseparatedbyan=character, andeachpairisdelimitedbyan&character. Forexample: key1=val1&key2=val2 Eachpayloadhasrulesgoverning:requiredvalues,URIencoding, parametersthatcanbesenttogether,andparameterlength.Alsoeach parameterhasaspecifictypethatrequiresaparticularformat.The followingsectionsgoesthroughtheserules. ReadtheParameterReference foracompletelistingofalltheparametersyoucansend usingtheMeasurementProtocol. RequiredValuesForAllHits Thefollowingparametersmustbeineachpayload: Name Parameter Example Description ProtocolVersion v v=1 Theprotocolversion.Thevalueshouldbe1. TrackingID tid tid=UA-123456-1 TheIDthatdistinguishestowhichGoogleAnalyticsproperty tosenddata. ClientID cid cid=xxxxx AnIDuniquetoaparticularuser. HitType t t=pageview Thetypeofinteractioncollectedforaparticularuser. TheClientIDandHitType dataarevaluesthatmapdirectlytotheGoogleAnalyticsdatamodel. Ifyouwantedtotrackuser5555whowentto /pageA,/pageB,and/pageC, youwouldsendthefollowing3payloads: v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageB v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageC Noticethatthe/wasencodedto%2F. URLEncodingValues AllvaluessenttoGoogleAnalyticsmustbebothUTF-8and URLEncoded. Tosendthekeydpwiththevalue /mypage€,youwillfirstneedtomakesurethisis UTF-8encoded,thenurlencoded,resultinginthefinalstring: dp=%2Fmy%20page%20%E2%82%AC Ifanyofthecharactersareencodedincorrectly,theywillbereplaced withtheunicodereplacementcharacterxFFFD. RequiredValuesForCertainHitTypes Someparametersmayonlybesentwithspecifichittypes. Forexample,thepageviewhittyperequiresthatthe PagePathparameter(dp)alsobeset.The ParameterReferencedescribes whichparametersarerequiredforwhichhittypes. MaximumLength SometextvaluesintheMeasurementProtocolhavespecificmaximumlengths inbytes.Forexample,thedocumentreferrerfield drhasamaximum lengthof2,048Bytes.Ifanyofthevaluesaregreaterthanthe maximumlengths,theywillautomaticallybetruncated.Ifamulti-byte characterexceedsthemaximumlength,theentirecharacterwill betruncated. SupportedDataTypes EachdatafieldintheMeasurementProtocolbelongstoaspecific type,eachwithitsownvalidation rules.Ifanyoftheparametervaluesdonotconformtothevalidationrules, thatspecificparameterwillbeignoredandnotprocessedbyGoogleAnalytics. Allotherparameterswillbeprocessedasnormal. Note:Ifarequiredparameteris malformed,theentirepayloadwillnotbeprocessed.Forexample, sendingthevaluebogusfortherequiredhittype parameterwouldresultintheentirepayloadnotbeingprocessed. TheMeasurementProtocolsupportsthefollowingdatatypes: Text Currency Boolean Integer Number Notethatindividualdatafieldsmighthavetheirownrestrictions.Seethe FieldReferenceforacompletelistofallthe datafieldsandacceptedtypes. Text Usedtorepresentstrings.Additionalprocessingisdoneontextfields. Allleadingandtrailingwhitespacecharactersareremoved.Internalruns oftwoormorewhitespacechars(includingspace,tab,newlines,etc) arereducedtoasinglespacecharacter.Thistransformationisapplied totherawtextbeforeanytruncationhappens.Forexample: HelloWorld willbecome: HelloWorld Currency Usedtorepresentthetotalvalueofacurrency.Adecimalpoint isusedasadelimiterbetweenthewholeandfractionalportion ofthecurrency.Theprecisionisupto6decimalplaces.Thefollowing isvalidforacurrencyfield: 1000.000001 OncethevalueissenttoGoogleAnalytics,alltextisremovedupuntil thefirstdigit,the-characterorthe. (decimal)character.So: $-55.00 willbecome: -55.00 Boolean Usedtodetermineifavalueistrueorfalse.Validvaluesare: 1–True 0–False Integer Usedtorepresentaninteger.Thevalueisstoredasasignedint64 Number Usedtorepresentanintegerorafloatingpointnumber. Exceptasotherwisenoted,thecontentofthispageislicensedundertheCreativeCommonsAttribution4.0License,andcodesamplesarelicensedundertheApache2.0License.Fordetails,seetheGoogleDevelopersSitePolicies.JavaisaregisteredtrademarkofOracleand/oritsaffiliates. Lastupdated2020-12-04UTC. [{ "type":"thumb-down", "id":"missingTheInformationINeed", "label":"MissingtheinformationIneed" },{ "type":"thumb-down", "id":"tooComplicatedTooManySteps", "label":"Toocomplicated/toomanysteps" },{ "type":"thumb-down", "id":"outOfDate", "label":"Outofdate" },{ "type":"thumb-down", "id":"samplesCodeIssue", "label":"Samples/codeissue" },{ "type":"thumb-down", "id":"otherDown", "label":"Other" }] [{ "type":"thumb-up", "id":"easyToUnderstand", "label":"Easytounderstand" },{ "type":"thumb-up", "id":"solvedMyProblem", "label":"Solvedmyproblem" },{ "type":"thumb-up", "id":"otherUp", "label":"Other" }] GitHub TryGoogleAnalyticssamples StackOverflow Askquestionsusingthegoogle-analyticstag Twitter Follow@googleanalyticsonTwitter Videos ViewGoogleAnalyticsvideosonYouTube Connect Community&Updates GettingHelp ReportinganIssue ProductInfo Protocol/SDKPolicy BrandingPolicy Developerconsoles GoogleAPIConsole GoogleCloudPlatformConsole GooglePlayConsole FirebaseConsole ActionsonGoogleConsole CastSDKDeveloperConsole ChromeWebStoreDashboard Android Chrome Firebase GoogleCloudPlatform Allproducts Terms Privacy SignupfortheGoogleDevelopersnewsletter Subscribe Language English BahasaIndonesia Deutsch Español Français Português–Brasil Русский 中文–简体 日本語 한국어
延伸文章資訊
- 1Measurement Protocol Reference - Google Developers
https://www.google-analytics.com/collect. All data should be sent securely with the HTTPS protoco...
- 2[GA4] Data collection - Analytics Help - Google Support
- 3What is Google Analytics and how does it work? - TechTarget
- 4Measurement Protocol in Google Analytics - Tutorial
POST http://www.google-analytics.com/collect. Transport is made up of: #1 GET/POST method – which...
- 5Regional data collection - Analytics Help - Google Help
When Analytics establishes a connection with the closest available Google data collection center,...