diff --git a/CHANGELOG.md b/CHANGELOG.md index 43ea14c..48a85d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tests/events/test_impression_util.py b/tests/events/test_impression_util.py index b079216..688bf73 100644 --- a/tests/events/test_impression_util.py +++ b/tests/events/test_impression_util.py @@ -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( diff --git a/vwo/api/activate.py b/vwo/api/activate.py index d5943aa..22cc6f9 100644 --- a/vwo/api/activate.py +++ b/vwo/api/activate.py @@ -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 ( @@ -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) diff --git a/vwo/api/is_feature_enabled.py b/vwo/api/is_feature_enabled.py index 908ede4..fb2e25e 100644 --- a/vwo/api/is_feature_enabled.py +++ b/vwo/api/is_feature_enabled.py @@ -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) @@ -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: diff --git a/vwo/helpers/impression_util.py b/vwo/helpers/impression_util.py index 07bb969..d016cff 100644 --- a/vwo/helpers/impression_util.py +++ b/vwo/helpers/impression_util.py @@ -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: @@ -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,