Skip to content

Instantly share code, notes, and snippets.

View superstrong's full-sized avatar

Robbie Mitchell superstrong

View GitHub Profile
@superstrong
superstrong / intercom-segment-tagger.gs
Last active March 3, 2020 03:00
[Moved to https://github.com/superstrong/intercom-segment-tagger] Retrieves users or companies in a given Intercom segment, then applies a desired tag to them.
function intercomTagger() {
// Make it your own
var target = "contacts"; // set to either "contacts" or "companies"
var desiredTag = "Test failure tag"; // e.g., "New Tag 1". Tag name must match exactly.
// If target is companies and the tag name doesn't exist, a new tag will be created
// If target is contacts and the tag name doesn't exist, the task will fail with an explanation
var segmentId = ""; // e.g., "5c1d18fddf74c998cb0a9dcd" get this from the URL while viewing a segment
var ownerEmail = ""; // email address to notify of errors and optional script results
var sendResultEmails = true; // true or false -- do you want to be notified every time the script runs?
@superstrong
superstrong / airtable-table-ids.js
Last active July 14, 2017 20:32
A bookmarklet. Get the name and ID of every table in the Airtable base you are currently viewing.
javascript:(function() {
var refTable = location.pathname.split('/')[1];
var source = initData.lastTableIdsUsedByApplicationId;
var apps = Object.keys(source);
var tables = Object.values(source);
for (var i = 0; i < tables.length; i++) {
if (tables[i] === refTable) {
var j = i;
i = tables.length;
@superstrong
superstrong / google-script-basecrm-api.js
Created November 19, 2016 02:13
Retrieve JSON data from the BaseCRM API and add it to a Google Sheet. This example retrieves all users. Stands on the shoulders of https://gist.github.com/varun-raj/5350595a730a62ca1954
function getBaseUsers() {
var options = {
"contentType" : "application/json",
"headers" : {
"Accept": "application/json",
"Authorization": "Bearer <TOKEN>"
}
}
var response = UrlFetchApp.fetch("https://api.getbase.com/v2/users", options);
var ss = SpreadsheetApp.getActiveSpreadsheet();
@superstrong
superstrong / google-script-asana-api.js
Created November 19, 2016 02:10
Retrieve JSON data from the Asana API and add it to a Google Sheet. This example retrieves all the users in a workspace. Stands on the shoulders of https://gist.github.com/varun-raj/5350595a730a62ca1954
function getAsanaUsers() {
var options = {
"headers" : {
"Authorization": "Bearer <TOKEN>"
}
}
var response = UrlFetchApp.fetch("https://app.asana.com/api/1.0/workspaces/<workspace-id>/users", options);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
@superstrong
superstrong / Code.gs
Created March 22, 2016 16:27
Google Script to generate a UUID in Google Sheets
function getId() {
/**
* Imported from https://github.com/kyo-ago/UUID
* Robbie Mitchell, @superstrong
*/
/**
* UUID.core.js: The minimal subset of the RFC-compliant UUID generator UUID.js.
*
* @fileOverview
@superstrong
superstrong / mailchimp-ajax-segment
Last active March 11, 2016 03:28
Add proper Segment tracking to your Mailchimp signup form
userId is a better way to join data at the user level across various tracking/email/etc. services. Why?
- UserId is stable (e.g., update a user's email address from anywhere by calling Segment identify with the same userId.)
- UserId is not PII (e.g., Google Analytics explicitly forbids using PII as a userId)
So, in addition to manually adding a subscriber to your Mailchimp list, this will explicitly assign a userId to each new subscriber and identify the user via Segment.
Quick steps:
- Get your Mailchimp list embed code here: Lists -> {list} -> Signup forms -> Embedded forms
- Use it to replace the three values in the "action" line below with your own. Also change "us6" if yours is different.
- In the hidden input field with id "bot-field", replace the name with the one from your own embed code.
@superstrong
superstrong / segment-identify-no-db
Last active March 9, 2016 00:43
Segment db-less identify
This code is for a website that collects email addresses but no registrations (e.g., passwords, etc.). The requirements for the project go further, but this is a necessary first step.
Project requirements:
- Simplify tracking implementation
- Use a userId, not email address, as primary key
- Avoid using a database on email-only website
Segment is useful as a canonical tracker -- a single place to track identity, pageviews. It works best, though, when a server generates a userId and calls `identify`, ensuring the userId passed through to all connected services.
Here, in lieu of a server-generated userId, we check for a Segment userId in the cookie. If it exists, we use it. If it doesn't, we grab Segment's anonymousId and re-use it as userId. This, along with the other form fields in a simple form, are used in an `identify` call that ensures all connected services get the same userId.
@superstrong
superstrong / zip_code_exploder.gs
Last active June 29, 2017 17:14
A Google Script that transforms a zip code into city, state zip via zippopotam.us
// Example use in a cell: "=map(90210)" (without quotes)
// Example output: "Beverly Hills, CA 90210"
function map(zip_code) {
// Make HTTP Request
var url = 'http://api.zippopotam.us/us/' + zip_code;
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
@superstrong
superstrong / knewton_hubspot_redirection
Created August 26, 2014 18:30
Knewton HubSpot Redirection Page with Spinner
<html>
<head>
<title>{{ content.html_title }}</title>
<meta name="description" content="{{ content.meta_description }}"/>
<meta name="robots" content="noindex">
<style>
.spinner {
position: fixed;
top: 50%;
left: 50%;
@superstrong
superstrong / gmail-permalink
Created April 3, 2014 17:31
[Browser bookmarklet] To generate a permalink to a Gmail message: (1) Open the email (2) Click "Show original (3) Run bookmarklet. You can share the search query (useful for when either party is logged into more than one Gmail account) or share the browser URL. Source: http://stackoverflow.com/questions/16827485/using-gmail-message-source-genera…