TagsBundle

open class TagsBundle

Immutable, thread-safe collection of tags for user segmentation and personalization.

TagsBundle stores key-value pairs that represent user attributes, preferences, and behaviors. Tags enable targeted push notifications, audience segmentation, and personalized content delivery through the Pushwoosh platform. Once built, a TagsBundle instance is immutable and can be safely shared across threads.

Building vs Reading Tags:

  • Use Builder when you need to create a custom tag collection for multiple operations
  • Use Tags utility methods for simple, one-off tag operations
  • Use sendTags to sync tags with Pushwoosh servers

Supported Tag Types:

  • Integer - for demographics, counters, scores (age, level, points)
  • Long - for timestamps, large IDs (registration_timestamp, user_id)
  • Boolean - for flags, subscriptions (email_subscribed, premium_user)
  • String - for profile data, categories (name, gender, favorite_category)
  • List - for multi-value attributes (interests, purchased_products)
  • Date - for milestones, events (last_purchase, subscription_end)

Thread Safety: TagsBundle is immutable after creation. The Builder uses ConcurrentHashMap to allow safe concurrent tag additions during construction.

Usage Example (E-commerce App):


// Building tags for a premium customer
TagsBundle tags = new TagsBundle.Builder()
    .putString("customer_tier", "premium")
    .putInt("lifetime_orders", 15)
    .putLong("customer_since", System.currentTimeMillis())
    .putBoolean("newsletter_subscribed", true)
    .putList("favorite_categories", Arrays.asList("electronics", "books"))
    .putDate("last_purchase", new Date())
    .build();

// Sending tags to Pushwoosh
Pushwoosh.getInstance().sendTags(tags);

// Reading tags from bundle
String tier = tags.getString("customer_tier"); // "premium"
int orders = tags.getInt("lifetime_orders", 0); // 15
List<String> categories = tags.getList("favorite_categories"); // ["electronics", "books"]

// Converting to JSON for API calls
JSONObject json = tags.toJson();

See also

<a href="http://docs.pushwoosh.com/docs/segmentation-tags-and-filters">Segmentation guide</a>

Types

Link copied to clipboard
open class Builder
Builder for constructing TagsBundle instances using the Builder pattern.

Functions

Link copied to clipboard
open fun getBoolean(key: String, defaultValue: Boolean): Boolean
Retrieves a boolean tag value by name, with a fallback default value.
Link copied to clipboard
open fun getInt(key: String, defaultValue: Int): Int
Retrieves an integer tag value by name, with a fallback default value.
Link copied to clipboard
open fun getList(key: String): List<String>
Retrieves a list tag value by name, or null if not found.
Link copied to clipboard
open fun getLong(key: String, defaultValue: Long): Long
Retrieves a long tag value by name, with a fallback default value.
Link copied to clipboard
open fun getMap(): Map<String, Any>
Returns the internal map representation of tags.
Link copied to clipboard
open fun getString(key: String): String
Retrieves a string tag value by name, or null if not found.
Link copied to clipboard
open fun toJson(): JSONObject
Converts the TagsBundle to its JSON representation.