Skip to content

Instantly share code, notes, and snippets.

View ak--47's full-sized avatar

AK ak--47

View GitHub Profile
@ak--47
ak--47 / mixpanel-heartbeat.js
Created June 11, 2025 20:08
Mixpanel Heartbeat API
/**
* @fileoverview Mixpanel Heartbeat API Extension
*
* Augments Mixpanel SDK with heartbeat() functionality for event aggregation.
* Useful for tracking continuous activities like video/audio playback, reading progress, etc...
* This API aggregates small events into summary events before sending to Mixpanel
*
* @author AK: ak@mixpanel.com
* @version 1.0.1
*/
@ak--47
ak--47 / event_data.xml
Created February 6, 2025 16:01
an XML file
<?xml version="1.0" encoding="UTF-8"?>
<events>
<event>
<timestamp>2025-02-06T12:34:56Z</timestamp>
<user_id>12345</user_id>
<event_id>c1d2e3f4-5678-9101-1121-314151617181</event_id>
<event_type>click</event_type>
<page_url>https://example.com/home</page_url>
<duration>5.3</duration>
<is_logged_in>true</is_logged_in>
@ak--47
ak--47 / event_data.csv
Last active February 6, 2025 15:51
a CSV file
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 16 columns, instead of 7 in line 5.
event_id,timestamp,user_id,event_type,page_url,time_spent_seconds,is_mobile,referrer,click_coordinates,items_in_cart,user_agent,browser_language,is_ad_blocker_enabled,favorite_colors,notes,is_conversion
1,2023-10-01T12:34:56Z,101,page_view,https://example.com/home,45,TRUE,https://google.com,"-1,024,768",3,Mozilla/5.0 (Windows NT 10.0; Win64; x64),en-US,TRUE,"blue,green",User loves cats.,FALSE
2,2023-10-01T12:35:10Z,102,click,https://example.com/products,10,FALSE,https://bing.com,"-800,600",,Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7),en-GB,FALSE,"red,orange",,TRUE
3,2023-10-01T12:36:22Z,103,add_to_cart,https://example.com/product/123,30,TRUE,https://yahoo.com,"-12,801,024",1,Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X),fr-FR,TRUE,"purple,yellow",User left a funny comment.,FALSE
4,2023-10-01T12:37:45Z,104,page_view,https://example.com/about,120,FALSE,,,,Mozilla/5.0 (Linux; Android 10; SM-G975F),de-DE,FALSE,"black,white",,FALSE
5,2023-10-01T12:38:50Z,105,purchase,https://example.com/checkout,60,TR
@ak--47
ak--47 / candivore.md.md
Created November 26, 2024 15:01
candivore.md

Candivore: POC + Path Forward

Snowplow's Schema

Snowplow is a state-of-the-art data collection platform which advocates for self-describing-objects. This means that events (rows) that travel through Snowplow's pipeline have a highly nested and hierarchical structure:

{
  "event": "user_transaction",
  "time": 1730592005,
  "APP_ID": "Match-Masters",
@ak--47
ak--47 / example.json
Created November 14, 2024 14:48
weird duckDb unnesting thing
{"origRow": 1, "foo":42,"bar":"fortyTwo","myNest":[{"hello":"space","goodbye":"world"},{"hello":"time","goodbye":"gravity"}]}
{"origRow": 2, "foo":420,"bar":"fortyTwenty","myNest":[{"hello":"you","goodbye":"me"},{"hello":"we","goodbye":"thee"}]}
@ak--47
ak--47 / upload-file-to-bucket.py
Created September 30, 2024 01:04
scrappy single upload
import os
from google.cloud import storage # pip install google-cloud-storage
# important! replace these variables with your values
bucket_name = 'mixpanel-poc'
source_file_name = 'source_file.json'
destination_blob_name = 'destination_file.json'
key_file_path = 'keyfile.json' # this file should be in your current working directory..
@ak--47
ak--47 / merchandising-evars.js
Last active August 16, 2024 04:05
Mixpanel / Adobe: Event Model + Hit Model
/***
*
* MIXPANEL vs ADOBE ANALYTICS
* merchandising eVars and client side attribution πŸ‘Ž
* sending events and passing objects with properties πŸ‘
*/
// ADOBE ANALYTICS: merchandising eVars and client side attribution
@ak--47
ak--47 / changes.sql
Last active June 3, 2024 04:32
Present State β†’ Future State
{{
config(
materialized='incremental',
unique_key='insert_id',
on_schema_change='sync_all_columns',
incremental_strategy='delete+insert'
)
}}
{% set present_table = source('time_flip', 'present') %}
@ak--47
ak--47 / segment-and-mixpanel.html
Last active May 16, 2024 13:31
Segment + Mixpanel w/Session Replay
<!-- segment snippet -->
<script>
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t,e){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";
analytics.load("SEGMENT-API-KEY");
anal
@ak--47
ak--47 / amp-to-mp.sh
Created April 12, 2024 17:51
Amplitude β†’ Mixpanel
#!/bin/bash
# move data from Amplitude to Mixpanel
# by AK (ak@mixpanel.com)
# set env vars (customize these!)
export START_DATE=2023-04-20
export END_DATE=2023-04-20
export AMPLITUDE_KEY=my_key
export AMPLITUDE_SECRET=my_secret
export MIXPANEL_TOKEN=my_key