def _mp_track(**kwargs):
if g.user_agent['browser']['name'] == 'QuiltCli':
source = 'cli'
else:
source = 'web'
# Use the user ID if the user is logged in; otherwise, let MP use the IP address.
distinct_id = g.auth.user if g.auth.user != PUBLIC else None
# Try to get the ELB's forwarded IP, and fall back to the actual IP (in dev).
ip_addr = request.headers.get('x-forwarded-for', request.remote_addr)
# Set common attributes sent with each event. kwargs cannot override these.
all_args = dict(
kwargs,
time=time.time(),
ip=ip_addr,
user=g.auth.user,
source=source,
browser_name=g.user_agent['browser']['name'],
browser_version=g.user_agent['browser']['version'],
platform_name=g.user_agent['platform']['name'],
platform_version=g.user_agent['platform']['version'],
deployment_id=DEPLOYMENT_ID,
)
mp.track(distinct_id, MIXPANEL_EVENT, all_args)
评论列表
文章目录