HitBuilders
Stay organized with collections
Save and categorize content based on your preferences.
Helper class to build a map of hit parameters and values.
Examples:This will send a event hit type with the specified parameters and a custom dimension
parameter.
Tracker t = // get a tracker.
t.send(new HitBuilders.EventBuilder()
.setCategory("EventCategory")
.setAction("EventAction")
.setCustomDimension(1, "dimension1")
.build());
If you want to send a parameter with all hits, set it on Tracker directly.
t.setScreenName("Home");
t.send(new HitBuilders.SocialBuilder()
.setNetwork("Google+")
.setAction("PlusOne")
.setTarget("SOME_URL")
.build());
t.send(new HitBuilders.SocialBuilder()
.setNetwork("Google+")
.setAction("Share")
.setTarget("SOME_POST")
.build());
t.send(new HitBuilders.SocialBuilder()
.setNetwork("Google+")
.setAction("HangOut")
.setTarget("SOME_CIRCLE")
.build());
You can override a value set on the tracker by adding it to the map.
t.setScreenName("Home");
t.send(new HitBuilders.EventBuilder()
.setScreenName("Popup Screen")
.setCategory("click")
.setLabel("popup")
.build());
Additionally, The builder objects can be re-used to build values to be sent with multiple
hits. HitBuilders.TimingBuilder tb = new HitBuilders.TimingBuilder()
.setCategory("category")
.setValue(0L)
.setVariable("name");
t.send(tb.setValue(10).build());
t.send(tb.setValue(20).build());
Nested Class Summary
class
This class is deprecated. This class has
been deprecated in favor of the new ScreenViewBuilder class. The two classes are
semantically similar but the latter is consistent across all the Google Analytics
platforms.
class
A Builder object to build event hits.
class
Exception builder allows you to measure the
number and type of caught and uncaught crashes and exceptions that occur in your
app.
class
Internal class to provide common builder class
methods.
class
This class is deprecated. This class has
been deprecated in favor of a richer set of APIs on all the HitBuilder classes. With
the new approach, simply use addProduct, addImpression, addPromo and setAction to add
ecommerce data to any of the hits.
class
Class to build a screen view hit.
class
A Builder object to build social event
hits.
class
Hit builder used to collect timing related
data.
class
This class is deprecated. This class has
been deprecated in favor of a richer set of APIs on all the HitBuilder classes. With
the new approach, simply use addProduct, addImpression, addPromo and setAction to add
ecommerce data to any of the hits.
Public Constructor Summary
Inherited Method Summary
From class java.lang.Object
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eHitBuilders\u003c/code\u003e class helps to construct maps of parameters and values for Google Analytics hit types, such as events, social interactions, and screen views.\u003c/p\u003e\n"],["\u003cp\u003eIt provides various nested builder classes like \u003ccode\u003eEventBuilder\u003c/code\u003e, \u003ccode\u003eSocialBuilder\u003c/code\u003e, and \u003ccode\u003eScreenViewBuilder\u003c/code\u003e to easily create different hit types with specific parameters.\u003c/p\u003e\n"],["\u003cp\u003eYou can set parameters directly on the \u003ccode\u003eTracker\u003c/code\u003e object for values to be sent with all hits, and override them using individual hit builders for specific cases.\u003c/p\u003e\n"],["\u003cp\u003eThe builder objects can be reused and modified to send multiple hits with varying values.\u003c/p\u003e\n"],["\u003cp\u003eSome older nested classes like \u003ccode\u003eAppViewBuilder\u003c/code\u003e, \u003ccode\u003eItemBuilder\u003c/code\u003e, and \u003ccode\u003eTransactionBuilder\u003c/code\u003e have been deprecated in favor of more comprehensive APIs.\u003c/p\u003e\n"]]],["`HitBuilders` is a helper class for creating hit parameter maps. To send data, create a builder object (e.g., `EventBuilder`, `SocialBuilder`) and use methods like `setCategory`, `setAction` to set parameters. Use `build()` to create the hit, then `send()` it via a tracker. Set parameters directly on the tracker for all hits, and override these values when sending specific hits. Builder objects are reusable. The nested class provides different builders for specific hit types.\n"],null,["# HitBuilders\n\npublic class **HitBuilders** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nHelper class to build a map of hit parameters and values.\n\nExamples: \n\nThis will send a event hit type with the specified parameters and a custom dimension\nparameter. \n\n```\n Tracker t = // get a tracker.\n t.send(new HitBuilders.EventBuilder()\n .setCategory(\"EventCategory\")\n .setAction(\"EventAction\")\n .setCustomDimension(1, \"dimension1\")\n .build());\n \n```\n\nIf you want to send a parameter with all hits, set it on Tracker directly. \n\n```\n t.setScreenName(\"Home\");\n t.send(new HitBuilders.SocialBuilder()\n .setNetwork(\"Google+\")\n .setAction(\"PlusOne\")\n .setTarget(\"SOME_URL\")\n .build());\n t.send(new HitBuilders.SocialBuilder()\n .setNetwork(\"Google+\")\n .setAction(\"Share\")\n .setTarget(\"SOME_POST\")\n .build());\n t.send(new HitBuilders.SocialBuilder()\n .setNetwork(\"Google+\")\n .setAction(\"HangOut\")\n .setTarget(\"SOME_CIRCLE\")\n .build());\n \n```\n\nYou can override a value set on the tracker by adding it to the map. \n\n```\n t.setScreenName(\"Home\");\n t.send(new HitBuilders.EventBuilder()\n .setScreenName(\"Popup Screen\")\n .setCategory(\"click\")\n .setLabel(\"popup\")\n .build());\n \n```\nAdditionally, The builder objects can be re-used to build values to be sent with multiple hits. \n\n```\n HitBuilders.TimingBuilder tb = new HitBuilders.TimingBuilder()\n .setCategory(\"category\")\n .setValue(0L)\n .setVariable(\"name\");\n t.send(tb.setValue(10).build());\n t.send(tb.setValue(20).build());\n \n``` \n\n### Nested Class Summary\n\n|-------|---|---|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| class | [HitBuilders.AppViewBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.AppViewBuilder) || *This class is deprecated. This class has been deprecated in favor of the new ScreenViewBuilder class. The two classes are semantically similar but the latter is consistent across all the Google Analytics platforms.* |\n| class | [HitBuilders.EventBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.EventBuilder) || A Builder object to build event hits. |\n| class | [HitBuilders.ExceptionBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.ExceptionBuilder) || Exception builder allows you to measure the number and type of caught and uncaught crashes and exceptions that occur in your app. |\n| class | [HitBuilders.HitBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.HitBuilder)\\\u003cT extends [HitBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.HitBuilder)\\\u003e || Internal class to provide common builder class methods. |\n| class | [HitBuilders.ItemBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.ItemBuilder) || *This class is deprecated. This class has been deprecated in favor of a richer set of APIs on all the HitBuilder classes. With the new approach, simply use addProduct, addImpression, addPromo and setAction to add ecommerce data to any of the hits.* |\n| class | [HitBuilders.ScreenViewBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.ScreenViewBuilder) || Class to build a screen view hit. |\n| class | [HitBuilders.SocialBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.SocialBuilder) || A Builder object to build social event hits. |\n| class | [HitBuilders.TimingBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.TimingBuilder) || Hit builder used to collect timing related data. |\n| class | [HitBuilders.TransactionBuilder](/android/reference/com/google/android/gms/analytics/HitBuilders.TransactionBuilder) || *This class is deprecated. This class has been deprecated in favor of a richer set of APIs on all the HitBuilder classes. With the new approach, simply use addProduct, addImpression, addPromo and setAction to add ecommerce data to any of the hits.* |\n\n### Public Constructor Summary\n\n|---|------------------------------------------------------------------------------------------------|\n| | [HitBuilders](/android/reference/com/google/android/gms/analytics/HitBuilders#HitBuilders())() |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Constructors\n-------------------\n\n#### public **HitBuilders** ()"]]