Skip to content

Instantly share code, notes, and snippets.

@hijonathan
hijonathan / inline.html
Created August 2, 2021 00:59
Implementing next/previous post functionality in Webflow with js. See https://www.mokupet.com/resources for a live example.
<script type="text/javascript">
/*
* Heavily based on https://discourse.webflow.com/t/native-linking-to-previous-and-next-post-or-page-using-cms/19525/19
* This one uses regular ol' javascript instead of jQuery.
*
* # How this script works:
*
* 1. It looks for a hidden collection on the page and gets all the items in it.
* 2. Using the current item, it identifies the items before and after it.
* 3. It then looks for the prev and next buttons on the page and updates those with the correct links.
/**
* Passphrase.
* Simple passphrase entry
*/
const accessMap = {
"tennessee": ['Caroline', 'Clay'],
"leia": ['Dog Walkers'],
"coffee": ['Jonathan', 'Connie']
};
(function(w, doc) {
const cookieKey = 'your_cookie';
let hasCookie = doc.cookie.split(';').filter((c) => {
let [k, _v] = c.split('=');
return k == cookieKey;
}).length > 0;
if (!hasCookie) {
@hijonathan
hijonathan / example.js
Created February 28, 2017 22:42
Send Appcues form responses into Intercom
// Add the following snippet to your application after loading Appcues and Intercom.
Appcues.on('form_submitted', function(data) {
var responses = {};
// Intercom doesn't like special characters.
var slugify = function(str) {
return str.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
@hijonathan
hijonathan / jql.js
Last active July 19, 2016 15:01
See Appcues form responses in Mixpanel JQL
function main() {
var date = new Date(),
prev30Date = new Date(date - 30*24*60*60*1000),
today = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`,
prev30 = `${prev30Date.getFullYear()}-${prev30Date.getMonth() + 1}-${prev30Date.getDate()}`;
return Events({
from_date: prev30,
to_date: today,
event_selectors: [{event: "Form Submitted (Appcues)"}]
@hijonathan
hijonathan / index.html
Created May 28, 2016 01:05
Appcues + Intercom
<!-- ... Appcues scripts installed higher up ... -->
<!-- Intercom Installation -->
<script>
window.intercomSettings = {
// TODO: The current logged in user's full name
name: 'Jonathan Kim',
user_id: '123456',
first_name: 'Jonathan',
email: 'get@me.bro.com',
@hijonathan
hijonathan / snippet.html
Last active May 24, 2016 19:30
Using Appcues + Segment with anonymous visitors. This snippet can safely be added to your site via Google Tag Manager.
<script>
(function() {
if (analytics != null && analytics.ready != null) {
analytics.ready(function() {
if (window.Appcues != null) {
if (analytics.user().id()) {
// Identify known user.
Appcues.identify(analytics.user().id(), analytics.user().traits());
} else {
// Identify as an anonymous user.
@hijonathan
hijonathan / index.html
Created May 4, 2016 00:08
How to implement Appcues without Segment, but pull in Segment user attributes if available.
<!-- Load Appcues ourselves, not using Segment. -->
<script src="//fast.appcues.com/23.js"></script>
<script>
// Listen for important events being passed to Segment.
analytics.on('identify', function(userId, traits) {
Appcues.identify(userId, traits);
});
analytics.on('page', function() {
Appcues.start();
});
@hijonathan
hijonathan / example.js
Created March 9, 2016 04:01
How to send Appcues Form Submission data to Segment
Appcues.on('flow_form_submission', function(eventData) {
// Convert the responses into an object where the field label is the key and the input
// is the value.
var responsesObj = {};
// Note: if your form labels are long, you may want to shorten them in this step.
// E.g. Convert "What is your email?" to "email" in the `forEach` loop.
eventData.response.forEach(function(resp) { responseObj[resp.label] = resp.value });
// Track that the event happened.
analytics.track('Appcues Form Submitted', {
@hijonathan
hijonathan / router.js
Created February 25, 2016 15:11
How to add Appcues to your Backbone application.
var AppRouter = Backbone.Router.extend({
beforeNavigate: function(fragment) {
// Put code you want to run before the URL changes.
},
afterNavigate: function(fragment) {
// Put code you want to run after the URL changes.
// Wait for all other javascript to finish running, then call Appcues.
window.setTimeout(function() {
if (Appcues != null && Appcues.start != null) Appcues.start();