@@ -70,6 +70,7 @@ def __init__(
7070 environment_key : typing .Optional [str ] = None ,
7171 api_url : typing .Optional [str ] = None ,
7272 realtime_api_url : typing .Optional [str ] = None ,
73+ analytics_url : typing .Optional [str ] = None ,
7374 custom_headers : typing .Optional [typing .Dict [str , typing .Any ]] = None ,
7475 request_timeout_seconds : typing .Optional [int ] = 10 ,
7576 enable_local_evaluation : bool = False ,
@@ -92,6 +93,11 @@ def __init__(
9293 Required unless offline_mode is True.
9394 :param api_url: Override the URL of the Flagsmith API to communicate with
9495 :param realtime_api_url: Override the URL of the Flagsmith real-time API
96+ :param analytics_url: Override the URL used for flag analytics requests when
97+ enable_analytics is True. When unset, analytics are posted to
98+ ``<api_url>/analytics/flags/``. Set this when api_url points at a host that
99+ does not handle analytics (for example, the Edge Proxy) so analytics can be
100+ sent directly to the core Flagsmith API.
95101 :param custom_headers: Additional headers to add to requests made to the
96102 Flagsmith API
97103 :param request_timeout_seconds: Number of seconds to wait for a request to
@@ -172,14 +178,12 @@ def __init__(
172178 self .session .proxies .update (proxies or {})
173179 retries = retries or Retry (total = 3 , backoff_factor = 0.1 )
174180
175- api_url = api_url or DEFAULT_API_URL
176- self .api_url = api_url if api_url .endswith ("/" ) else f"{ api_url } /"
177-
178- realtime_api_url = realtime_api_url or DEFAULT_REALTIME_API_URL
179- self .realtime_api_url = (
180- realtime_api_url
181- if realtime_api_url .endswith ("/" )
182- else f"{ realtime_api_url } /"
181+ self .api_url = self ._ensure_trailing_slash (api_url or DEFAULT_API_URL )
182+ self .realtime_api_url = self ._ensure_trailing_slash (
183+ realtime_api_url or DEFAULT_REALTIME_API_URL
184+ )
185+ self .analytics_url = (
186+ self ._ensure_trailing_slash (analytics_url ) if analytics_url else None
183187 )
184188
185189 self .request_timeout_seconds = request_timeout_seconds
@@ -201,21 +205,30 @@ def __init__(
201205 self ._initialise_analytics (
202206 environment_key = environment_key ,
203207 enable_analytics = enable_analytics ,
208+ analytics_url = self .analytics_url ,
204209 )
205210 self ._initialise_events (
206211 environment_key = environment_key ,
207212 enable_events = enable_events ,
208213 event_processor_config = event_processor_config ,
209214 )
210215
216+ @staticmethod
217+ def _ensure_trailing_slash (url : str ) -> str :
218+ return url if url .endswith ("/" ) else f"{ url } /"
219+
211220 def _initialise_analytics (
212221 self ,
213222 environment_key : str ,
214223 enable_analytics : bool ,
224+ analytics_url : typing .Optional [str ] = None ,
215225 ) -> None :
216226 if enable_analytics :
217227 self ._analytics_processor = AnalyticsProcessor (
218- environment_key , self .api_url , timeout = self .request_timeout_seconds
228+ environment_key ,
229+ self .api_url ,
230+ timeout = self .request_timeout_seconds ,
231+ analytics_url = analytics_url ,
219232 )
220233
221234 def _initialise_events (
0 commit comments