Tags
class Tags
Utility class for creating single-tag TagsBundle instances quickly.
Tags are key-value pairs that store user attributes and behavior data on the device. They enable audience segmentation for targeted push campaigns, personalized messaging, and behavioral tracking. Use tags to store user profile data, preferences, activity metrics, and any other information needed for campaign targeting.
When to Use Tags vs TagsBundle.Builder:
- Use Tags static methods when setting a single tag quickly
- Use TagsBundle.Builder when setting multiple tags in one operation (more efficient)
Tag Types and Use Cases:
- Integer - numeric values like age, purchase count, loyalty points, app version
- Long - large numbers like timestamps, user IDs, milliseconds since epoch
- Boolean - yes/no values like subscription status, email verified, premium user
- String - text values like name, city, subscription tier, language preference
- List - multiple values like favorite categories, interests, viewed product IDs
- Date - timestamps like last login, registration date, last purchase date
Tag Operations:
- Set - use intTag, stringTag, etc. to set or update tag values
- Increment - use incrementInt to add to existing numeric values
- Append - use appendList to add items to existing lists
- Remove - use removeFromList to remove items from lists or removeTag to delete tags
Best Practices:
- Use descriptive tag names in PascalCase or snake_case (e.g., "Subscription_Tier", "last_purchase_date")
- Keep tag names consistent across your app
- Use predefined values for categorical tags (e.g., "free", "basic", "premium" for subscription tiers)
- Combine multiple tag updates using TagsBundle.Builder to reduce network calls
- Remove unused tags with removeTag to keep your data clean
Complete Usage Example:
// E-commerce app: Track user profile and shopping behavior
// 1. Set user profile on login
TagsBundle userProfile = new TagsBundle.Builder()
.putString("Name", "John Smith")
.putInt("Age", 32)
.putString("City", "New York")
.putString("Subscription_Tier", "premium") // "free", "basic", "premium"
.putBoolean("Email_Verified", true)
.putDate("Registration_Date", new Date())
.build();
Pushwoosh.getInstance().setTags(userProfile);
// 2. Track shopping behavior with single tags (quick updates)
Pushwoosh.getInstance().setTags(Tags.stringTag("Last_Viewed_Category", "electronics"));
Pushwoosh.getInstance().setTags(Tags.dateTag("Last_Purchase", new Date()));
// 3. Increment purchase counter after successful order
Pushwoosh.getInstance().setTags(Tags.incrementInt("Total_Purchases", 1));
Pushwoosh.getInstance().setTags(Tags.incrementInt("Loyalty_Points", 50));
// 4. Add to favorite categories list
List<String> newFavorites = Arrays.asList("electronics", "sports");
Pushwoosh.getInstance().setTags(Tags.appendList("Favorite_Categories", newFavorites));
// 5. Remove from wishlist when purchased
List<String> purchasedItems = Arrays.asList("product_12345");
Pushwoosh.getInstance().setTags(Tags.removeFromList("Wishlist", purchasedItems));
// 6. News app: Track reading preferences
Pushwoosh.getInstance().setTags(Tags.listTag("Interests", Arrays.asList("technology", "business", "sports")));
Pushwoosh.getInstance().setTags(Tags.intTag("Articles_Read_Today", 5));
Pushwoosh.getInstance().setTags(Tags.booleanTag("Breaking_News_Enabled", true));
// 7. Fitness app: Track user activity
Pushwoosh.getInstance().setTags(Tags.intTag("Workouts_This_Week", 4));
Pushwoosh.getInstance().setTags(Tags.stringTag("Fitness_Level", "intermediate"));
Pushwoosh.getInstance().setTags(Tags.dateTag("Last_Workout", new Date()));
// 8. Clean up: Remove deprecated tags
Pushwoosh.getInstance().setTags(Tags.removeTag("Old_Field_Name"));
Content copied to clipboard
See also
Functions
Link copied to clipboard
Creates a TagsBundle that appends values to an existing list tag.
Link copied to clipboard
Creates a TagsBundle with a single boolean tag.
Link copied to clipboard
Creates a TagsBundle with a single date tag.
Link copied to clipboard
Returns an empty TagsBundle singleton instance.
Link copied to clipboard
Creates a TagsBundle from a JSON object.
Link copied to clipboard
Creates a TagsBundle that increments an integer tag value.
Link copied to clipboard
Creates a TagsBundle with a single integer tag.
Link copied to clipboard
Creates a TagsBundle with a single long integer tag.
Link copied to clipboard
Creates a TagsBundle that removes values from an existing list tag.
Link copied to clipboard
Creates a TagsBundle that removes a tag from the device.
Link copied to clipboard
Creates a TagsBundle with a single string tag.