Skip to content

Commit 993609a

Browse files
avoid trying to track without an analytics write_key
1 parent 2096cf1 commit 993609a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

app/app.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def ask():
4040

4141
if not query:
4242
return jsonify({"error": "No query provided"}), 400
43-
43+
4444
# For analytics tracking, generates an anonymous id and uses it for the session
4545
if 'anonymous_id' not in session:
4646
session['anonymous_id'] = str(uuid.uuid4())
@@ -59,12 +59,13 @@ def generate():
5959
if not full_response:
6060
full_response = "No response generated"
6161

62-
# Track the query and response
63-
analytics.track(
64-
anonymous_id=anonymous_id,
65-
event='Chatbot Question submitted',
66-
properties={'query': query, 'response': full_response, 'source': 'Ask Defang'}
67-
)
62+
if analytics.write_key:
63+
# Track the query and response
64+
analytics.track(
65+
anonymous_id=anonymous_id,
66+
event='Chatbot Question submitted',
67+
properties={'query': query, 'response': full_response, 'source': 'Ask Defang'}
68+
)
6869

6970
return Response(stream_with_context(generate()), content_type='text/markdown')
7071

0 commit comments

Comments
 (0)