Skip to content

Instantly share code, notes, and snippets.

View timgl's full-sized avatar

timgl timgl

View GitHub Profile
const API_URL = 'https://app.posthog.com/';
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,HEAD,POST,OPTIONS',
'Access-Control-Max-Age': '86400',
};
const ORIGIN = new URL(API_URL).origin
@timgl
timgl / testhash.py
Last active January 12, 2022 18:29
__LONG_SCALE__ = float(0xFFFFFFFFFFFFFFF)
import hashlib
import secrets
def hash(identifier):
hash_key = f"test.{identifier}.{secrets.token_hex(32)}"
hash_val = int(hashlib.sha1(hash_key.encode("utf-8")).hexdigest()[:15], 16)
# In your time-sensitive process
tracker = Mixpanel::Tracker.new(YOUR_POSTHOG_TOKEN) do |type, message|
@queue.set('mixpanel_queue', [ type, message ].to_json)
end
# Track just like you would in any other situation
tracker.track(user_id, 'Sent Message')
tracker.people.increment(user_id, {
'Messages Sent' => 1
})
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>'