Skip to content

Instantly share code, notes, and snippets.

@hijonathan
hijonathan / segment.js
Created June 10, 2015 21:01
Send Appcues events through Segment's Analytics.js.
Appcues.on('all', function(eventId, data) {
if (analytics != null && analytics.track && eventId === 'flow_analytics') {
var desc = typeof data === 'string' ? data : data.description;
analytics.track(desc, Appcues.user());
}
}
@hijonathan
hijonathan / style.css
Created May 28, 2015 18:31
Appcues button styling
/* Set the color of the back buttons to Appcues blue. */
.appcues-button {
background-color: #4baad3;
}
.appcues-button:hover {
background-color: #247294; /* A bit darker. */
}
.appcues-button.appcues-button-success {
@hijonathan
hijonathan / main.js
Created May 27, 2015 15:27
Appcues RequireJS installation
requirejs.config({
"paths": {
"appcues": "//fast.appcues.com/<your_appcues_id>"
}
});
// Later in your app.
define(['models/user', 'appcues'], function(user, Appcues) {
Appcues.identify(user.id, {
email: user.email,
@hijonathan
hijonathan / scrape-globals.js
Created March 3, 2015 19:46
Get the custom-defined variables from the global window object.
// Ensure our properties aren't tracked.
(function () {
var currentWindow,
result = {},
iframe = document.createElement('iframe');
// Get a clean window object from this iframe.
iframe.style.display = 'none';
document.body.appendChild(iframe);
@hijonathan
hijonathan / footer.php
Created January 30, 2015 19:42
Appcues WordPress installation
@hijonathan
hijonathan / templatize.coffee
Last active August 29, 2015 14:06
Super simple js templating
# Regex for ONE optional whitespace.
# NOTE: Replace `?` with `*` to make it more lenient.
nbsp = '[\\s\\xA0]\?'
templatize = (str, context) ->
# If no object just return string.
if not context or typeof context isnt 'object'
return str
# Loop through keys and replace placeholders.
@hijonathan
hijonathan / snippet.js
Created August 29, 2014 01:24
Appcues + VWO integration.
var _vis_opt_queue = window._vis_opt_queue || [], _vis_counter = 0;
_vis_opt_queue.push(function() {
try {
if(!_vis_counter) {
var _vis_data = {},_vis_combination,_vis_id,_vis_l=0;
for(;_vis_l<_vwo_exp_ids.length;_vis_l++) {
_vis_id = _vwo_exp_ids[_vis_l];
if(_vwo_exp[_vis_id].ready) {
_vis_combination = _vis_opt_readCookie('_vis_opt_exp_'+_vis_id+'_combi');
if(typeof(_vwo_exp[_vis_id].combination_chosen) != "undefined")
@hijonathan
hijonathan / ajaxNavigate.js
Created August 12, 2014 21:40
Adding pushState with Appcues.
// Example click handler that uses pushState and Appcues.
$('.tab-navigation').on('click', 'a[href]', function(e) {
if (window.history && window.history.pushState) {
// Update the URL without reloading the page.
window.history.pushState({}, document.title, e.currentTarget.getAttribute('href'));
// Re-check Appcues against this new URL.
Appcues.check();
}
@hijonathan
hijonathan / config.js
Last active August 29, 2015 14:04
Using AppcuesIdentity config object.
// Create a special global variable that the Appcues script will look for upon load.
// Admittedly, this should probably be called "AppcuesConfig".
window.AppcuesIdentity = window.AppcuesIdentity || {
appcuesId: 'foo',
userId: 1234,
userEmail: '[email protected]'
};
// Asynchronously load Appcues embed script.
asyncLoadAppcues().then(function() {
@hijonathan
hijonathan / example.coffee
Last active November 11, 2024 01:34
Javascript implementation of the largest remainder method http://en.wikipedia.org/wiki/Largest_remainder_method
values = [
13.626332
47.989636
9.596008
28.788024
]
# Round these percentage values into integers, ensuring that they equal 100% at the end.
roundedValues = getLargestRemainder values, 100
# [14, 48, 9, 29]