Builder

open class Builder

Builder for constructing TagsBundle instances using the Builder pattern.

The Builder allows efficient, fluent construction of tag collections through method chaining. All tag additions are stored client-side until build is called to create an immutable TagsBundle. The actual synchronization with Pushwoosh servers happens when you call sendTags.

Thread Safety: This builder uses ConcurrentHashMap internally, making it safe to add tags from multiple threads during construction.

Batching Best Practice: When setting multiple tags, always use a single Builder instance and one sendTags call instead of multiple individual tag operations. This reduces network requests and improves performance.

Usage Example (Fitness App):


	TagsBundle userProfile = new TagsBundle.Builder()
	    // Demographics
	    .putInt("age", 28)
	    .putString("gender", "female")
	    .putString("fitness_level", "intermediate")
	
	    // Activity tracking
	    .putInt("workouts_completed", 45)
	    .putDate("last_workout", new Date())
	    .putList("favorite_activities", Arrays.asList("yoga", "running", "cycling"))
	
	    // Subscription status
	    .putBoolean("premium_member", true)
	    .putLong("subscription_end", System.currentTimeMillis() + 30L * 24 * 60 * 60 * 1000)
	
	    // Preferences
	    .putBoolean("push_workouts", true)
	    .putBoolean("push_achievements", true)
	    .build();
	
	// Send all tags in one request
	Pushwoosh.getInstance().sendTags(userProfile);
	

See also

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
Appends values to an existing list tag without replacing the entire list.
Link copied to clipboard
open fun build(): TagsBundle
Builds and returns an immutable TagsBundle instance with all added tags.
Link copied to clipboard
Link copied to clipboard
open fun incrementInt(key: String, value: Int): TagsBundle.Builder
Increments an integer tag by the specified value without fetching the current value first.
Link copied to clipboard
open fun putAll(json: JSONObject): TagsBundle.Builder
Imports all tags from a JSON object, adding them to the builder.
Link copied to clipboard
Adds a tag with a boolean value.
Link copied to clipboard
open fun putDate(key: String, value: Date): TagsBundle.Builder
Adds a tag with a date value, formatted as "yyyy-MM-dd HH:mm".
Link copied to clipboard
open fun putInt(key: String, value: Int): TagsBundle.Builder
Adds a tag with an integer value.
Link copied to clipboard
open fun putList(key: String, value: List<String>): TagsBundle.Builder
Adds a tag with a list of string values, replacing any existing list.
Link copied to clipboard
open fun putLong(key: String, value: Long): TagsBundle.Builder
Adds a tag with a long value.
Link copied to clipboard
open fun putString(key: String, value: String): TagsBundle.Builder
Adds a tag with a string value.
Link copied to clipboard
Adds a tag with a string value only if the value is not null or empty.
Link copied to clipboard
Removes a tag from the user's profile on Pushwoosh servers.
Link copied to clipboard
Removes specific values from an existing list tag without replacing the entire list.