Skip to content

Commit

Permalink
Disable geoip for capture and decide calls by default (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
  • Loading branch information
liyiy and neilkakkar authored Apr 17, 2023
1 parent 4aa3499 commit 617bb53
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 29 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## 3.0.0 - 2023-04-14

Breaking change:

All events by default now send the `$geoip_disable` property to disable geoip lookup in app. This is because usually we don't
want to update person properties to take the server's location.

The same now happens for feature flag requests, where we discard the IP address of the server for matching on geoip properties like city, country, continent.

To restore previous behaviour, you can set the default to False like so:

```python
posthog.disable_geoip = False

# // and if using client instantiation:
posthog = Posthog('api_key', disable_geoip=False)

```

## 2.5.0 - 2023-04-10

1. Add option for instantiating separate client object
Expand Down
24 changes: 24 additions & 0 deletions posthog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
personal_api_key = None # type: str
project_api_key = None # type: str
poll_interval = 30 # type: int
disable_geoip = True # type: bool

default_client = None

Expand All @@ -30,6 +31,7 @@ def capture(
uuid=None, # type: Optional[str]
groups=None, # type: Optional[Dict]
send_feature_flags=False,
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
"""
Expand Down Expand Up @@ -62,6 +64,7 @@ def capture(
uuid=uuid,
groups=groups,
send_feature_flags=send_feature_flags,
disable_geoip=disable_geoip,
)


Expand All @@ -71,6 +74,7 @@ def identify(
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
"""
Expand All @@ -95,6 +99,7 @@ def identify(
context=context,
timestamp=timestamp,
uuid=uuid,
disable_geoip=disable_geoip,
)


Expand All @@ -104,6 +109,7 @@ def set(
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
"""
Expand All @@ -128,6 +134,7 @@ def set(
context=context,
timestamp=timestamp,
uuid=uuid,
disable_geoip=disable_geoip,
)


Expand All @@ -137,6 +144,7 @@ def set_once(
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
"""
Expand All @@ -161,6 +169,7 @@ def set_once(
context=context,
timestamp=timestamp,
uuid=uuid,
disable_geoip=disable_geoip,
)


Expand All @@ -171,6 +180,7 @@ def group_identify(
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
"""
Expand All @@ -196,6 +206,7 @@ def group_identify(
context=context,
timestamp=timestamp,
uuid=uuid,
disable_geoip=disable_geoip,
)


Expand All @@ -205,6 +216,7 @@ def alias(
context=None, # type: Optional[Dict]
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
"""
Expand All @@ -230,6 +242,7 @@ def alias(
context=context,
timestamp=timestamp,
uuid=uuid,
disable_geoip=disable_geoip,
)


Expand All @@ -241,6 +254,7 @@ def feature_enabled(
group_properties={}, # type: dict
only_evaluate_locally=False, # type: bool
send_feature_flag_events=True, # type: bool
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> bool
"""
Expand All @@ -265,6 +279,7 @@ def feature_enabled(
group_properties=group_properties,
only_evaluate_locally=only_evaluate_locally,
send_feature_flag_events=send_feature_flag_events,
disable_geoip=disable_geoip,
)


Expand All @@ -276,6 +291,7 @@ def get_feature_flag(
group_properties={}, # type: dict
only_evaluate_locally=False, # type: bool
send_feature_flag_events=True, # type: bool
disable_geoip=None, # type: Optional[bool]
):
"""
Get feature flag variant for users. Used with experiments.
Expand Down Expand Up @@ -308,6 +324,7 @@ def get_feature_flag(
group_properties=group_properties,
only_evaluate_locally=only_evaluate_locally,
send_feature_flag_events=send_feature_flag_events,
disable_geoip=disable_geoip,
)


Expand All @@ -317,6 +334,7 @@ def get_all_flags(
person_properties={}, # type: dict
group_properties={}, # type: dict
only_evaluate_locally=False, # type: bool
disable_geoip=None, # type: Optional[bool]
):
"""
Get all flags for a given user.
Expand All @@ -334,6 +352,7 @@ def get_all_flags(
person_properties=person_properties,
group_properties=group_properties,
only_evaluate_locally=only_evaluate_locally,
disable_geoip=disable_geoip,
)


Expand All @@ -346,6 +365,7 @@ def get_feature_flag_payload(
group_properties={},
only_evaluate_locally=False,
send_feature_flag_events=True,
disable_geoip=None, # type: Optional[bool]
):
return _proxy(
"get_feature_flag_payload",
Expand All @@ -357,6 +377,7 @@ def get_feature_flag_payload(
group_properties=group_properties,
only_evaluate_locally=only_evaluate_locally,
send_feature_flag_events=send_feature_flag_events,
disable_geoip=disable_geoip,
)


Expand All @@ -366,6 +387,7 @@ def get_all_flags_and_payloads(
person_properties={},
group_properties={},
only_evaluate_locally=False,
disable_geoip=None, # type: Optional[bool]
):
return _proxy(
"get_all_flags_and_payloads",
Expand All @@ -374,6 +396,7 @@ def get_all_flags_and_payloads(
person_properties=person_properties,
group_properties=group_properties,
only_evaluate_locally=only_evaluate_locally,
disable_geoip=disable_geoip,
)


Expand Down Expand Up @@ -418,6 +441,7 @@ def _proxy(method, *args, **kwargs):
project_api_key=project_api_key,
poll_interval=poll_interval,
disabled=disabled,
disable_geoip=disable_geoip,
)

# always set incase user changes it
Expand Down
Loading

0 comments on commit 617bb53

Please sign in to comment.