When sending custom events with attributes using the Pushwoosh Flutter SDK, the data types of your attributes (e.g., boolean, integer, string, list) are determined as follows:
Define Events in Control Panel (Recommended):
- The best practice is to first define your custom event and its attributes, including their specific data types, directly in the Pushwoosh Control Panel.
- Go to your application in the Pushwoosh Control Panel, navigate to the Events section, and create or edit your event, specifying each attribute's name and its intended type (e.g., "isSubscribed" as Boolean, "itemCount" as Integer).
Sending Events from Flutter SDK:
- When you use the
postEvent
method in your Flutter application, you provide a map of attributes. The keys should be the attribute names (as strings), and the values should be of the native Dart data types that correspond to what you defined in the Control Panel or intend for automatic creation.// Example: Pushwoosh.postEvent("myCustomEvent", attributes: { "productName": "Example Item", // String "quantity": 2, // Integer "isAvailable": true, // Boolean "tags": ["new", "featured"] // List of Strings });
- The Flutter SDK will automatically interpret the data type of the values you pass (e.g.,
true
is a boolean,10
is an integer,"text"
is a string,['a', 'b']
is a list). You do not explicitly pass atype
parameter for each attribute within thepostEvent
call itself, as you might see in some direct API documentation examples.
- When you use the
Automatic Event and Attribute Creation:
- If you send an event using
postEvent
that has not yet been defined in the Pushwoosh Control Panel, Pushwoosh will attempt to automatically create the event and its attributes. - The data types for these automatically created attributes will be inferred from the values sent in the first
postEvent
call for that new event. For instance, if you send{"myAttribute": true}
, "myAttribute" will generally be created as a boolean type. If you send{"myAttribute": 1}
, it will generally be created as an integer.
- If you send an event using
Correcting Attribute Data Types:
- If an attribute's data type was incorrectly set or inferred (e.g., a boolean value was sent as
0
or1
and interpreted as an integer initially), you cannot directly change the data type of that attribute for an existing event in the Control Panel. - To address this:
- If the event was auto-created with an incorrect type, you may need to delete the event definition in the Pushwoosh Control Panel (if feasible and no critical historical data for that specific event structure is lost).
- Then, either re-create the event manually in the Control Panel with the correct attribute types before sending data, or ensure the first
postEvent
call for this event (or a new version of the event) sends attributes with the correct native Dart data types for proper automatic type inference. - The most reliable method to ensure correct typing is to pre-define the event and its attribute types in the Control Panel before sending any data for that event.
- If an attribute's data type was incorrectly set or inferred (e.g., a boolean value was sent as
By following these guidelines, you can ensure that your custom event attributes are stored with their intended data types in Pushwoosh.
Comments
0 comments
Please sign in to leave a comment.