Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ gb = GrowthBook(
plugins=[
request_context_plugin(), # Extracts request data
growthbook_tracking_plugin(
ingestor_host="https://gb-ingest.growthbook.io",
ingestor_host="https://us-east-1.gb-ingest.com",
# Optional: Add custom tracking callback
additional_callback=my_custom_tracker
)
Expand Down
4 changes: 2 additions & 2 deletions growthbook/plugins/growthbook_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class GrowthBookTrackingPlugin(GrowthBookPlugin):

def __init__(
self,
ingestor_host: str = "https://us1.gb-ingest.com",
ingestor_host: str = "https://us-east-1.gb-ingest.com",
track_experiment_viewed: bool = True,
track_feature_evaluated: bool = True,
batch_size: int = 10,
Expand All @@ -106,7 +106,7 @@ def __init__(
Initialize GrowthBook tracking plugin.
Args:
ingestor_host: Base URL of the GrowthBook ingestor (default: ``https://us1.gb-ingest.com``).
ingestor_host: Base URL of the GrowthBook ingestor (default: ``https://us-east-1.gb-ingest.com``).
track_experiment_viewed: Whether to auto-track experiment viewed events.
track_feature_evaluated: Whether to auto-track feature evaluated events.
batch_size: Number of events to accumulate before flushing to the ingestor.
Expand Down
36 changes: 32 additions & 4 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import asyncio
import json
import pytest
import threading
import unittest
from unittest.mock import patch, MagicMock
from growthbook import (
Expand Down Expand Up @@ -465,9 +466,11 @@ def my_logger(event_name, properties, user_context):
def test_log_event_with_plugin_sends_correct_payload(self):
"""Plugin wires the event logger; log_event triggers an ingestor POST."""
posted = []
sent = threading.Event()

def fake_post(url, data, headers, timeout):
posted.append({"url": url, "body": json.loads(data), "headers": headers})
sent.set()
response = MagicMock()
response.status_code = 200
return response
Expand All @@ -478,14 +481,14 @@ def fake_post(url, data, headers, timeout):
client_key="sdk-test-key",
plugins=[
growthbook_tracking_plugin(
ingestor_host="https://us1.gb-ingest.com",
ingestor_host="https://us-east-1.gb-ingest.com",
batch_size=1, # flush immediately
)
],
)
gb.log_event("checkout_started", {"cart_value": 99})
# Give the daemon thread a moment to post
import time; time.sleep(0.05)
# The POST runs on a daemon thread; wait for it while requests.post is still patched
self.assertTrue(sent.wait(timeout=2), "tracking did not send events")

self.assertEqual(len(posted), 1, "Expected exactly one POST")
url = posted[0]["url"]
Expand All @@ -509,6 +512,31 @@ def fake_post(url, data, headers, timeout):
self.assertEqual(posted[0]["headers"]["Content-Type"], "text/plain")
gb.destroy()

def test_default_ingestor_host_is_us_east_1(self):
"""Without ingestor_host, events go to the us-east-1 ingest host."""
posted = []
sent = threading.Event()

def fake_post(url, data, headers, timeout):
posted.append(url)
sent.set()
response = MagicMock()
response.status_code = 200
return response

with patch("requests.post", side_effect=fake_post):
gb = GrowthBook(
attributes={"id": "user-42"},
client_key="sdk-test-key",
plugins=[growthbook_tracking_plugin(batch_size=1)],
)
gb.log_event("checkout_started", {})
# The POST runs on a daemon thread; wait for it while requests.post is still patched
self.assertTrue(sent.wait(timeout=2), "tracking did not send events")

self.assertEqual(posted, ["https://us-east-1.gb-ingest.com/track?client_key=sdk-test-key"])
gb.destroy()

def test_log_event_empty_properties(self):
"""log_event works with no properties argument."""
received = []
Expand Down Expand Up @@ -605,7 +633,7 @@ def test_async_client_plugin_wires_event_logger(self):
Options(
client_key="sdk-key",
tracking_plugins=[
growthbook_tracking_plugin(ingestor_host="https://us1.gb-ingest.com")
growthbook_tracking_plugin(ingestor_host="https://us-east-1.gb-ingest.com")
],
)
)
Expand Down
Loading