Skip to content

Commit

Permalink
add /decide
Browse files Browse the repository at this point in the history
  • Loading branch information
jbwyme committed Feb 11, 2021
1 parent 6908143 commit 1d153d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Assuming you have Docker installed on your system, you can do the following:

1. Clone the repo
2. Build the Docker image: `docker build -t mixpanel-proxy .`
3. Run a container using the image: `docker run --name my-tracking-proxy -d -p 5000:5000 mixpanel-proxy`
3. Run a container using the image: `docker run -d -p 5000:5000 mixpanel-proxy`
4. Visit `http://localhost:5000`

### Option 3: Run the Flask application directly
Expand Down
4 changes: 2 additions & 2 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/**
* Configuration Variables - CHANGE THESE!
*/
const MIXPANEL_PROJECT_TOKEN = YOUR_PROJECT_TOKEN; // e.g. "67e8bfdec29d84ab2d36ae18c57b8535"
const MIXPANEL_PROXY_DOMAIN = YOUR_PROXY_URL; // e.g. "https://proxy-eoca2pin3q-uc.a.run.app"
const MIXPANEL_PROJECT_TOKEN = "6888bfdec29d84ab2d36ae18c57b8535"; // e.g. "67e8bfdec29d84ab2d36ae18c57b8535"
const MIXPANEL_PROXY_DOMAIN = "http://localhost:8080"; // e.g. "https://proxy-eoca2pin3q-uc.a.run.app"

/**
* Set the MIXPANEL_CUSTOM_LIB_URL - No need to change this
Expand Down
5 changes: 4 additions & 1 deletion flask_proxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def api_request(path):
more control over each request type.
"""

# /decide is hosted on a different subdomain
mixpanel_url = 'https://decide.mixpanel.com' if path == 'decide' else 'https://api.mixpanel.com'

# This relays the client's IP for geolocation lookup
# The method via which you can retrieve the "real" client IP
# is implementation specific so you may need to change this logic.
Expand All @@ -53,7 +56,7 @@ def api_request(path):
# pass the request directly to Mixpanel
resp = requests.request(
method=request.method,
url='https://api.mixpanel.com%s' % request.path,
url='%s/%s' % (mixpanel_url, path),
headers=headers,
params=request.args,
data=request.form,
Expand Down
12 changes: 11 additions & 1 deletion flask_proxy/tests/test_mixpanel_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,19 @@ def test_get_no_data(self, client):

def test_get(self, client):
resp = client.get('/groups?verbose=1&data=%s' % group_update_encoded)
print(resp.data)
assert resp.json['status'] == 1

def test_post(self, client):
resp = client.post('/groups', data={'verbose': 1, 'data': json.dumps(group_update)})
assert resp.json['status'] == 1

class TestDecide:
def test_get_no_data(self, client):
resp = client.get('/decide?verbose=1')
assert 'error' in resp.json
assert resp.json['error'] == 'token, missing or empty'

def test_get(self, client):
resp = client.get('/decide?verbose=1verbose=1&version=3&lib=web&token=fake-token&distinct_id=user%40example.com')
assert 'error' in resp.json
assert resp.json['error'] == 'token, no project found'

0 comments on commit 1d153d6

Please sign in to comment.