Skip to content

Instantly share code, notes, and snippets.

View sperand-io's full-sized avatar

Chris Sperandio sperand-io

  • CoPlane
View GitHub Profile
// analytics.page('Name', { returning: getNewOrRepeat() === 'repeat' })
function getNewOrRepeat() {
var session = 30; // minutes — feel free to change
var timeout = 30; // days — feel free to change
var cookie = '__nr' // cookie name — feel free to change
var now = new Date().getTime();
var day = 24 * 60 * 60 * 1000;
@sperand-io
sperand-io / index.js
Created January 26, 2016 18:51
Track Link Dynamic Properties Example
// links are DOM element(s) (multiple or singular)
//
// var links = document.querySelectorAll('a');
// var links = document.getElementByTagName('#specificLink')
analytics.trackLink(links, 'Clicked Link', function(link) {
return {
url: link.href,
@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