Skip to content

Instantly share code, notes, and snippets.

View sperand-io's full-sized avatar

Chris Sperandio sperand-io

  • Stripe
  • SF
View GitHub Profile
@sperand-io
sperand-io / index.md
Last active December 9, 2015 18:56
Installing V2 of Segment's iOS SDK

To build the SDK to be small and use the integrations server-side only, add the following to your Podfile:

  pod 'Analytics/Segmentio', '~> 2.0.9'
  ... and to add any individual bundled integrations:
  pod 'Analytics/GoogleAnalytics'
  pod 'Analytics/Mixpanel'
  ... // the subspecs for additional bundled integrations are all listed here:
  ... // https://github.com/CocoaPods/Specs/blob/master/Specs/Analytics/2.0.9/Analytics.podspec.json
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
/**
* The node posix path parser implemented in ES2015
*
* regex from: https://github.com/nodejs/node/blob/master/lib/path.js#L406
*
* @param {String} path
* @return {Object} result
*
* let { name } = parse('/foo/bar/baz.html')
* // => name: baz
@sperand-io
sperand-io / index.es6
Last active November 5, 2015 03:19
Track Youtube Views By Visitor (Like Wistia!)
// download youtube API by constructing script tag and inserting to dom
const el = document.getElementsByTagName('script')[0];
const script = document.createElement('script');
script.src = 'https://www.youtube.com/iframe_api';
el.parentNode.insertBefore(script, el);
// take an existing youtube player <iframe>
// and decorates with a state change handler
@sperand-io
sperand-io / index.js
Last active October 30, 2015 17:10
Wootric -> Segment
analytics.ready(function() {
window.wootricSetttings.survey_callback = function survey_callback() {
analytics.identify({ last_wootric_surveyed_at: Math.round((testDate.getTime())/1000) });
};
window.wootricSetttings.decline_callback = function decline_callback() {
analytics.identify({ last_wootric_declined_at : Math.round((testDate.getTime())/1000) });
};
window.wootricSetttings.response_callback = function response_submitted_callback(score, comment) {
@sperand-io
sperand-io / index.js
Last active September 7, 2020 12:09
Koa EventSource Streaming (SSE)
const PassThrough = require('stream').PassThrough;
const Router = require('koa-66');
const router = new Router();
const Koa = require('koa');
const app = new Koa();
// ...
const sse = (event, data) => {
return `event:${ event }\ndata: ${ data }\n\n`
duo index.js > build.js
@sperand-io
sperand-io / README.md
Last active August 29, 2015 14:27 — forked from tmcw/README.md
Line Chart
@sperand-io
sperand-io / instructions.md
Last active December 5, 2016 19:06
What Is Segment Sending on My Behalf?

If you have node installed, you can clone the repo for whichever integration you'd like to use (say GA) then install segmentio-facade:

git clone https://github.com/segmentio/integration-google-analytics.git
cd integration-google-analytics
npm install segmentio-facade

Then create a new file in the top level of the directory with the script from this gist.

@sperand-io
sperand-io / index.js
Last active September 2, 2015 22:16
Sending Some Traits to Some Tools But Not To Others!
// these are the trait keys you want to send to customer.io
var importantTraits = ['trait1', 'trait2', 'trait3'];
function identify(userId, traits) {
traits = extend({}, traits || {});
var matchingTraits = reduce(function(acc, val, key){
if (~importantTraits.indexOf(key)) acc[key] = val;
return acc;