Skip to content

Instantly share code, notes, and snippets.

View mattm's full-sized avatar

Matt Mazur mattm

View GitHub Profile
@mattm
mattm / mp-companies.lookml
Created April 6, 2018 18:23
Mixpanel Companies Derived Table
view: mp_companies {
derived_table: {
sql:
SELECT
distinct_id,
CAST(JSON_EXTRACT_SCALAR(properties, "$.com_id") AS INT64) AS com_id
FROM mp.event
WHERE name = "Signed Up" ;;
}
@mattm
mattm / visitor-flow.sql
Last active April 6, 2018 18:14
Visitor Path
SELECT
time,
name,
current_url
FROM (
SELECT
distinct_id,
CAST(JSON_EXTRACT_SCALAR(properties, "$.com_id") AS INT64) AS com_id
FROM mp.event
WHERE name = "Signed Up"
@mattm
mattm / com-id.sql
Created April 6, 2018 17:58
Extracting a JSON value
SELECT
properties,
JSON_EXTRACT_SCALAR(properties, "$.com_id") AS com_id
FROM mp.event
WHERE name = "Signed Up"
LIMIT 1
+-----------------+--------+
| properties | com_id |
+-----------------+--------+
@mattm
mattm / tokyo.sql
Created April 6, 2018 17:54
Page Views Example
SELECT COUNT(*) FROM mp.event WHERE city = "Tokyo" AND DATE(time) = "2018-04-03"
@mattm
mattm / signed-up.js
Created April 6, 2018 17:38
Tracking Sign Ups in Mixpanel
mixpanel.track("Signed Up", {
com_id: comId
});
@mattm
mattm / viewed-page.js
Created April 6, 2018 17:34
Tracking Page Views in Mixpanel
<script>
mixpanel.track("Viewed Page");
</script>
@mattm
mattm / referrer-bookmarklet.js
Created January 25, 2018 16:54
A bookmarklet to prompt you for a new document.referrer
javascript:(function(){
var newReferrer = prompt('Set the referrer:');
Object.defineProperty(document, "referrer", {configurable: true, get : function(){ return newReferrer; }})
})();
@mattm
mattm / deleted-records.sql
Last active January 29, 2018 15:19
Deleted Payment Records 2017+
SET @mpy_id = (SELECT MAX(mpy_id) + 1 from members_payments);
DROP TABLE IF EXISTS members_payments_all_ids;
CREATE TEMPORARY TABLE members_payments_all_ids AS (
SELECT @mpy_id := @mpy_id - 1 AS mpy_id
FROM members_payments mp1, members_payments mp2
WHERE @mpy_id > 1
);
@mattm
mattm / solution.sql
Last active January 3, 2018 18:45
Identifying Missing Primary Keys
SET @mpy_id = (SELECT MAX(mpy_id) + 1 from members_payments);
DROP TABLE IF EXISTS members_payments_all_ids;
CREATE TEMPORARY TABLE members_payments_all_ids AS (
SELECT @mpy_id := @mpy_id - 1 AS mpy_id
FROM members_payments mp1, members_payments mp2
WHERE @mpy_id > 1
);
@mattm
mattm / missing-records.sql
Last active January 3, 2018 18:45
Missing Records
SELECT mpy_id FROM members_payments WHERE mpy_id BETWEEN 1 AND 10;
+--------+
| mpy_id |
+--------+
| 1 |
| 4 |
| 6 |
| 9 |
| 10 |