Skip to content

Commit

Permalink
Added custom property in activate()
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitesh-wingify committed Dec 20, 2023
1 parent 25b5ecd commit 8661975
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.66.1] - 2023-12-20

### Added

- Added custom property in activate()

## [1.66.0] - 2023-11-22

### Fixed
Expand Down
33 changes: 33 additions & 0 deletions tests/events/test_impression_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,39 @@ def test_create_track_user_events_impression(self):

self.assertDictEqual(result, expected)

def test_create_track_user_events_impression_custom_property(self):
with mock.patch("vwo.helpers.generic_util.get_random_number", return_value="0.123456789"), mock.patch(
"vwo.helpers.generic_util.get_current_unix_timestamp", return_value="123456789"
), mock.patch("vwo.helpers.generic_util.get_current_unix_timestamp_milli", return_value="123456789000"):

expected = {
"d": {
"msgId": uuid_util.generate_for(TEST_USER_ID, TEST_ACCOUNT_ID)
+ "-"
+ str(generic_util.get_current_unix_timestamp_milli()),
"visId": uuid_util.generate_for(TEST_USER_ID, TEST_ACCOUNT_ID),
"sessionId": generic_util.get_current_unix_timestamp(),
"event": {
"props": {
"id": 1,
"variation": 1,
"isFirst": 1,
"vwo_sdkName": constants.SDK_NAME,
"vwo_sdkVersion": constants.SDK_VERSION,
"vwo_envKey": self.settings_file.get("sdkKey"),
"vwoMeta": { "textProperty": "python"}
},
"name": constants.EVENTS.VWO_VARIATION_SHOWN,
"time": generic_util.get_current_unix_timestamp_milli(),
},
"visitor": {"props": {"vwo_fs_environment": self.settings_file.get("sdkKey")}},
}
}

result = impression_util.create_track_user_events_impression(self.settings_file, 1, 1, TEST_USER_ID, custom_properties={'textProperty': 'python'})

self.assertDictEqual(result, expected)

def test_create_track_goal_events_impression_without_revenue(self):

with mock.patch("vwo.helpers.generic_util.get_random_number", return_value="0.123456789"), mock.patch(
Expand Down
3 changes: 2 additions & 1 deletion vwo/api/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _activate(vwo_instance, campaign_key, user_id, **kwargs):
variation_targeting_variables = kwargs.get("variation_targeting_variables")
user_agent = kwargs.get("user_agent")
user_ip_address = kwargs.get("user_ip_address")
custom_properties = kwargs.get("custom_properties") # to support custom properties in variationShown

# Validate input parameters
if (
Expand Down Expand Up @@ -150,7 +151,7 @@ def _activate(vwo_instance, campaign_key, user_id, **kwargs):
user_ip_address=user_ip_address,
)
impression = impression_util.create_track_user_events_impression(
vwo_instance.settings_file, campaign.get("id"), variation.get("id"), user_id
vwo_instance.settings_file, campaign.get("id"), variation.get("id"), user_id, custom_properties
)
vwo_instance.event_dispatcher.dispatch_events(params=params, impression=impression)

Expand Down
3 changes: 2 additions & 1 deletion vwo/api/is_feature_enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _is_feature_enabled(vwo_instance, campaign_key, user_id, **kwargs):
variation_targeting_variables = kwargs.get("variation_targeting_variables")
user_agent = kwargs.get("user_agent")
user_ip_address = kwargs.get("user_ip_address")
custom_properties = kwargs.get("custom_properties") # to support custom properties in variationShown

if (
not validate_util.is_valid_string(campaign_key)
Expand Down Expand Up @@ -149,7 +150,7 @@ def _is_feature_enabled(vwo_instance, campaign_key, user_id, **kwargs):
user_ip_address=user_ip_address,
)
impression = impression_util.create_track_user_events_impression(
vwo_instance.settings_file, campaign.get("id"), variation.get("id"), user_id
vwo_instance.settings_file, campaign.get("id"), variation.get("id"), user_id, custom_properties
)
vwo_instance.event_dispatcher.dispatch_events(params=params, impression=impression)
else:
Expand Down
4 changes: 3 additions & 1 deletion vwo/helpers/impression_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def get_stringified_log_impression(impression):
return json.dumps(log_impression)


def create_track_user_events_impression(settings_file, campaign_id, variation_id, user_id):
def create_track_user_events_impression(settings_file, campaign_id, variation_id, user_id, custom_properties=None):
"""Creates the event impression for track user call from the arguments passed accordingly
Args:
Expand All @@ -188,6 +188,8 @@ def create_track_user_events_impression(settings_file, campaign_id, variation_id

# impression["d"]["event"]["props"].update(UsageStats.get_usage_stats())
impression["d"]["event"]["props"].update({"id": campaign_id, "variation": variation_id, "isFirst": 1})
if custom_properties is not None:
impression["d"]["event"]["props"].update({"vwoMeta": custom_properties})

logger.log(
LogLevelEnum.DEBUG,
Expand Down

0 comments on commit 8661975

Please sign in to comment.