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 / 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
@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 July 4, 2024 19:27
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.