Skip to content

Instantly share code, notes, and snippets.

@timgl
Last active February 10, 2020 01:55
Show Gist options
  • Save timgl/b5e2a5cd87ca4775e52e0a584965557f to your computer and use it in GitHub Desktop.
Save timgl/b5e2a5cd87ca4775e52e0a584965557f to your computer and use it in GitHub Desktop.
from mixpanel import Mixpanel, Consumer, MixpanelException
class PostHogConsumer(Consumer):
_posthog_endpoints = {
'events': 'https://t.posthog.com/capture',
'people': 'https://t.posthog.com/engage',
'groups': 'https://t.posthog.com/groups',
'imports': 'https://t.posthog.com/import'
}
_posthog_api_key = '<posthog_key>'
def send(self, endpoint, json_message=None, api_key=None):
if endpoint in self._endpoints:
self._write_request(self._posthog_endpoints[endpoint], json_message, self._posthog_api_key)
self._write_request(self._endpoints[endpoint], json_message, api_key)
else:
raise MixpanelException('No such endpoint "{0}". Valid endpoints are one of {1}'.format(endpoint, self._endpoints.keys()))
mp = Mixpanel('<mixpanel_key>', consumer=PostHogConsumer())
mp.people_set('distinct_id', {'email': 'whatever@gmail.com'})
mp.track('distinct_id', 'some event')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment