Profile operation

Using Profile operation type objects

class ProfileOperation
add_rule(profile_property_id, values, strategy)

Add rule to apply on the profile.

Parameters:
  • profile_property_id (str) – the profile property ID this rule is for

  • values (Union[str, int, float, date, datetime, Sequence]) – value or list of values that will be applied to profile property

  • strategy (Strategy) – Strategy which determines how this rule will be applied

Usage:
>>> import blueconic
>>> from datetime import datetime
>>> bc = blueconic.Client()
>>>
>>> # Create matching properties which will be used to match account
>>> # Expected format {"property_id": "property_value"}
>>> matching_props = [{"email": "example@example.com"}]
>>> profile_operation = blueconic.ProfileOperation(matching_properties=matching_props)
>>>
>>> # Profile id can also be supplied to find the profile, as shown below
>>> # profile_operation = blueconic.ProfileOperation(profile_id="15037a96-863b-43a2-9e5c-c46fef77ff2e")
>>> # Set profile property "currentbrowsername" to "Chrome"
>>> profile_operation.add_rule("currentbrowsername", "Chrome", blueconic.Strategy.SET)
>>> profile_operation.add_rule("lastvisitdate", datetime.now(), blueconic.Strategy.SET)
>>> # Set first visit to 2022-09-23 15:30:00.12345
>>> profile_operation.add_rule("firstvisit", datetime(2022, 9, 23, 15, 30, 0, 12345), blueconic.Strategy.SET)
>>> # Set date of birth to 1993-09-23 9:23:25
>>> profile_operation.add_rule("date_of_birth", 748776205713, blueconic.Strategy.SET)
>>>
>>> # Save profile_operation using profile_bulkhandler
>>> with bc.get_profile_bulkhandler() as bh:
>>>     bh.write(profile_operation)
add_timeline_operation(operation)

Add operation to apply on the profiles’ timeline.

Parameters:

operation (Union[TimelineEvent, TimelineEventOperation]) – Timeline event or timeline event operation to apply on the profiles’ timeline

Usage:
>>> import blueconic
>>> from datetime import datetime
>>> bc = blueconic.Client()
>>> # Create matching properties which will be used to match account
>>> # Expected format {"property_id": "property_value"}
>>> matching_props = [{"email": "example@example.com"}]
>>> profile_operation = blueconic.ProfileOperation(matching_properties=matching_props)
>>> # Profile id can also be supplied to find the profile, as shown below
>>> # profile_operation = blueconic.ProfileOperation(profile_id="15037a96-863b-43a2-9e5c-c46fef77ff2e")
>>> timeline_operation = blueconic.TimelineEventOperation(
>>>     "abandoned_basket", blueconic.TimelineStrategy.UPSERT, event_id="abandoned_basket_2"
>>> )
>>> # Make change on top level property
>>> timeline_operation.add_rule("total_value", [5], blueconic.Strategy.SET)
>>> # Set order date to 2022-09-23 15:30:00
>>> timeline_operation.add_rule("order_date", datetime(2022, 9, 23, 15, 30, 0), blueconic.Strategy.SET)
>>> timeline_operation.add_rule("shipping_date", datetime.now(), blueconic.Strategy.SET)
>>>
>>> # #Nested-properties
>>> # Match nested property who's identifier is "987644321"
>>> nested_property_operation = blueconic.TimelineNestedItemOperation("id", "987644321")
>>>
>>> nested_property_operation.add_rule("quantity", [100], blueconic.Strategy.SET)
>>> nested_property_operation.add_rule("variant", ["variant1", "variant2"], blueconic.Strategy.SET)
>>> nested_property_operation.add_rule("variant", ["variant3", "variant4"], blueconic.Strategy.ADD)
>>>
>>> #There is root level property "product", add nested-properties to it
>>> timeline_operation.add_rule("product", [nested_property_operation], blueconic.TimelineStrategy.UPSERT)
>>>
>>> # Add the timeline_operation to profile_operation
>>> profile_operation.add_timeline_operation(timeline_operation)
>>>
>>> # Or to delete a timeline event, the DELETE strategy can be used
>>> remove_timeline_event_operation = = blueconic.TimelineEventOperation(
>>>     "abandoned_basket", blueconic.TimelineStrategy.DELETE, event_id="abandoned_basket_4", date_time=datetime(2020, 5, 17)
>>> )
>>> # Add the timeline_operation to profile_operation
>>> profile_operation.add_timeline_operation(remove_timeline_event_operation)
>>>
>>> # Save profile_operation using profile_bulkhandler
>>> with bc.get_profile_bulkhandler() as bh:
>>>     bh.write(profile_operation)
property identifier
Returns:

Returns the timeline operations to apply on the profiles’ timeline

Return type:

Optional[str]

property matching_properties
Returns:

Returns the matching properties for this profile operation.

Return type:

Optional[Sequence[Dict[str, Any]]]

property profile_id
Returns:

Returns the profile id.

Return type:

Optional[str]

property rules
Returns:

Returns the rules to apply for this profile operation.

Return type:

List[JsonDict]

property timeline_operations
Returns:

Returns the timeline operations to apply on the profiles’ timeline

Return type:

List[JsonDict]

Strategy

class Strategy

This enumeration defines all possible strategies for rules for profile properties and individual timeline event properties.

SET:

Replaces existing values with the given values.

ADD:

Adds given values to existing values.

SET_IF_EMPTY:

Only replaces the existing values with the given values when there are no existing values.

SUM:

For number properties, sums up the existing value with the given value.

INCREMENT:

For number properties, increments up the existing value with the given value.

REMOVE:

Removes given values from the existing values.