Importing Data from the BigQuery Tables
Letās consider how to create a BigQuery data source and use it for segmentation and personalization in Reteno.
Configuring a Data Source for Importing Data to Reteno
- Go to your profile ā Settings ā Data sources, click New data source, and select External data source.
- Select the created connector.
- Specify the dataset and table, and enter a source name (also you can specify filters for forming the message content here). Click Save.
Using BigQuery Data for Fitness App Campaigns Based on Engagement and Workout History
You can create personalized campaigns that dynamically reference user data like engagement level or workout history stored in BigQuery. Letās go through some examples of how to integrate this data into campaign messages.
1. Bulk Campaign with BigQuery Data
Suppose youāre running a bulk campaign aimed at encouraging highly engaged users to try new workout challenges. Hereās an example of how you might structure data for a campaign to a contact with the email [email protected] using the engagement_levels data source:
{
"data": {
"engagement_levels": [
{
"id": "2",
"email": "[email protected]",
"name": "Jordan Lee",
"lastWorkoutDate": "2023-10-15T10:00:00Z",
"workoutStreak": 15,
"averageWorkoutTime": 45
}
]
}
}You can reference each field in the message using a Velocity syntax as follows:
- Directly with parameters (when the number of array items is fixed):
$!data.get('engagement_levels').get(0).get('name')
$!data.get('engagement_levels').get(0).get('workoutStreak')- Using a loop (ideal for variable-length arrays):
#foreach($el in $!data.get('engagement_levels'))
$!el.get('name')
$!el.get('workoutStreak')
#end2. Triggered Campaign Based on Workout History
Letās say you want to send a message to users who reach a specific workout milestone, like completing 50 workouts. To do this, create a dynamic segment that includes only users whose workout history meets the milestone condition.
Set up a regular workflow for this segment.
When the workflow triggers for contacts matching specified conditions, the system creates an event. The event name is generated by combining the static prefix regularEventType with the segment ID, resulting in a name like regularEventType-170531841.
This event includes contact information, such as the contact ID in Reteno (contactId), email address (emailAddress), and data pulled from an external table. Each field from the table is converted into a key and placed within an array, labeled with a numeric name that matches the data source ID.
Data from the external table is passed in the system event as a native JSON object. Escaped JSON strings are not used, so no additional parsing is required to work with the data. Example event body:
{
"params": [
{
"name": "contactId",
"value": "123456789"
},
{
"name": "1043",
"value": [
{
"id": 2,
"email": "[email protected]",
"name": "Jordan Lee",
"lastPurchaseDate": "2023-10-15T10:00:00Z",
"purchaseFrequency": 50,
"averageBasketValue": 120
}
]
},
{
"name": "emailAddress",
"value": "[email protected]"
}
]
}When inserting data into a message, the Reteno data source ID is used as the array name in the data object:
{
"data": {
"1043": [
{
"id": "2",
"email": "[email protected]",
"name": "Jordan Lee",
"lastWorkoutDate": "2023-10-15T10:00:00Z",
"workoutStreak": 15,
"averageWorkoutTime": 45
}
]
}
}You can access the fields of the 1043 array in the message template in two ways:
- With parameters (if you know the number of items in the data array):
$!data.get('1043').get(0).get('name')
$!data.get('1043').get(0).get('workoutStreak')- Using a loop (ideal for flexible-length arrays):
#foreach($el in $!data.get('1043'))
$!el.get('name')
$!el.get('workoutStreak')
#endConfiguring Dynamic Segment by BigQuery Parameters
- Create the Dynamic segment (the Contacts ā Segments section).
- Select the conditions for inclusion in the segment. In the condition options, click the source name, then the option name, and set the condition. For example, CA ā started ā today:
- CA (Contact Activity) is the name of your data source,
- started is the fact of contact activity,
- today is the condition for the contact to join the group based on this parameter.
NoteConnection to the external database doesnāt presuppose contact import. Segmentation is only available for contacts that exist both in your Reteno account and in the external database. Synchronize and update contacts before creating campaigns.
Updated 4 days ago
