Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Sperandio sperand-io

  • Stripe
  • SF
View GitHub Profile
@sperand-io
sperand-io / segment-function.js
Last active Aug 28, 2020
segment events -> rockset
View segment-function.js
// https://segment.com/docs/connections/functions/destination-functions/
export const track = insertEvent
export const identify = insertEvent
export const page = insertEvent
export const screen = insertEvent
export const group = insertEvent
// https://docs.rockset.com/rest-api/#patchdocuments
const insertEvent = async (msg, { collection, workspace, apiKey }) => {
const endpoint = `https://api.rs2.usw2.rockset.com/v1/orgs/self/ws/${workspace}/collections/${collection}/docs`
@sperand-io
sperand-io / index.js
Last active Mar 30, 2020
Segment OCI Streaming Function
View index.js
async function track(e, settings) {
return await send(e, settings)
}
async function identify(e, settings) {
return await send(e, settings)
}
async function group(e, settings) {
return await send(e, settings)
View index.js
// adds a check (`g.auryc[fn] !== wrapper`) to prevent the recursion when auryc isn’t loaded yet
// fixed the usage of `arguments`
function safeInvoke(g, fn) {
return function wrapper() {
if (g.auryc && typeof g.auryc[fn] !== 'undefined' && g.auryc[fn] !== wrapper) {
g.auryc[fn].call(this, Array.prototype.slice.call(arguments, 0));
}
else {
g.aurycReadyCb.push(function () {
@sperand-io
sperand-io / index.js
Created Nov 5, 2018
Override errant referrers
View index.js
// on page with the payment/login button that they leave from
var link = document.getElementById('paymentOrLoginLinkElementID')
var href = link.getAttribute('href');
link.addEventListener('click', function(event){
// before progressing to the link, save the referrer
event.preventDefault();
sessionStorage.setItem('ctxReferrer', document.referrer);
window.location.href = href;
});
View keybase.md

Keybase proof

I hereby claim:

  • I am sperand-io on github.
  • I am sperandio (https://keybase.io/sperandio) on keybase.
  • I have a public key whose fingerprint is 8306 489A 5C3D 5795 190C D8BA BBC4 D1BD 40D1 8F90

To claim this, I am signing this object:

@sperand-io
sperand-io / snippet.html
Last active Jul 27, 2016
Set heap super props before initial page call
View snippet.html
<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","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){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.1.0";
// add this line below
window.heap = window.heap ||
View getNewOrRepeat.js
// 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 Jan 26, 2016
Track Link Dynamic Properties Example
View index.js
// 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 Dec 9, 2015
Installing V2 of Segment's iOS SDK
View index.md

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
View import_json_appsscript.js
/**
* 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();