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 / 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
@ak--47
ak--47 / user-agent-block.js
Created March 20, 2024 01:48
blocking user agents mixpanel
const express = require('express');
const app = express();
const Mixpanel = require('mixpanel')
const mixpanel = mixpanel.init('your token')
var BLOCKED_UA_STRS = [
'googlebot',
'googleweblight',
@ak--47
ak--47 / mp_azure_snowflake.sql
Last active January 28, 2024 18:56
MIXPANEL → AZURE → SNOWFLAKE pipeline
-- MIXPANEL → AZURE → SNOWFLAKE pipeline
-- the second half...
-- by ak@mixpanel.com
-- docs: https://docs.snowflake.com/en/user-guide/data-load-azure-create-stage
-- create storage integration
CREATE OR REPLACE STORAGE INTEGRATION azure_intergration
TYPE = EXTERNAL_STAGE
STORAGE_PROVIDER = AZURE
ENABLED = TRUE
@ak--47
ak--47 / manual-ETL-mp-azure.sh
Created January 23, 2024 16:49
Mixpanel /export + Azure Blob Storage
#!/bin/bash
# Set the necessary variables
MIXPANEL_API_URL="https://data.mixpanel.com/api/2.0/export"
AZURE_ACCOUNT_NAME="mystorageaccount"
AZURE_CONTAINER_NAME="mycontainer"
AUTHORIZATION_HEADER="Authorization: Basic {{ base64(mixpanel_secret) }}"
# Function to download data from Mixpanel and upload to Azure
download_and_upload() {
@ak--47
ak--47 / populate-mp.sh
Created June 1, 2023 20:03
populate a mixpanel project
# fill a mixpanel project with fake data
# set env vars (customize these)
export MP_SECRET=your-project-secret
# generate 100k events and send them
npx --yes carvis --mixpanel --rows 100000 | xargs npx --yes mixpanel-import --secret $MP_SECRET
@ak--47
ak--47 / reload-mp.sh
Last active January 2, 2024 16:14
reload mixpanel data
# reload all EVENTS from one project to another
# environment variables
# CUSTOMIZE THESE 👇
export START=2023-01-01
export END=2023-05-31
export SOURCE_SECRET=my-source-project-secret
export TARGET_SECRET=my-target-project-secret
# export → import
@ak--47
ak--47 / refreshMpDropdowns.js
Created March 27, 2023 18:22
refresh mixpanel dropdowns
#!/usr/bin/env node
/*
THE WONDERFUL EVENT/PROP DROPDOWN RESURFACER
--------------------------------------------
purpose:
mixpanel's dropdowns for events and props are great; but they only cache data that is from the last 30 days
this sucks if you are importing data that's older than 30 days
@ak--47
ak--47 / gtmMixpanelAutoCapture.md
Created March 10, 2023 18:34
GA4 / UA → Mixpanel (auto-binding)

GOAL: leverage existing GTM data in Mixpanel

essentially: bind mixpanel.track() calls to existing Universal Analytics + GA4 implementations without adding new triggers for each event

note: this is experimental... every product's GTM implementation is different... please test this in a sandbox before using in production

Step 1: Install the Mixpanel GTM Template to your GTM container


this module binds all of mixpanel's javascript SDK methods to an object that is native to the GTM container.

@ak--47
ak--47 / BqToMp.md
Last active March 8, 2023 19:23
☁️ BigQuery → Mixpanel
@ak--47
ak--47 / $merge.md
Last active July 10, 2022 02:45
mixpanel $merge in a nutshell

$merge in 5 mins

Assume 4 unique events (1 → 4) , each with a different distinct_id (A → D)

[{
     "event": 1,
     "properties": {"distinct_id": "A"} 
 },
 {
     "event": 2,