Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
def view_product(product_id):
# Log view_product event
user_id = flask.session["user"]
log_analytics_event('view_product', product_id, user_id, request.remote_addr)
return render_template('product.html', product=get_product(product_id))
@app.route('/purchase/<int:product_id>', methods=['POST'])
def purchase_product(product_id):
# Log purchase event
user_id = flask.session["user"]
log_analytics_event('purchase_product', product_id, user_id, request.remote_addr)
return jsonify({'message': 'Purchase successful!'})
# Function log_analytics_event
def log_analytics_event(event_type, event_data, user_id, user_ip):
# open a file called analytics.log
with open('analytics.log', 'a') as f:
f.write(f'{event_type}: {event_data} - User IP: {user_ip}- User ID: {user_id}\n')