Skip to content

Instantly share code, notes, and snippets.

@hijonathan
hijonathan / code.js
Last active February 18, 2016 20:06
Have Appcues check for new content after subtle changes to the URL.
// Notify Appcues about subtle URL changes, like a # getting added.
// Calling Appcues.start() will tell us to look for new content the user could qualify for.
(function() {
if ('onhashchange' of window) {
window.addEventListener('hashchange', function() {
if (Appcues && Appcues.start) Appcues.start;
})
}
})();
@hijonathan
hijonathan / example.js
Last active August 10, 2016 14:38
How to send Appcues form data to your HubSpot Enterprise account.
// If you're using HubSpot Enterprise Events, you can send Appcues form info to HubSpot like this.
// Appcues Forms Documentation: http://inside.appcues.com/docs/#flow_form_submission
// HubSpot Enterprise Documentation: http://developers.hubspot.com/docs/methods/enterprise_events/javascript_api
_hsq.push(['identify', {email: $user_email}]);
Appcues.on('form_submitted', function(eventData) {
// Track that the event happened.
_hsq.push(['trackEvent', {
id: 'appcues_form_submission_' + eventData.formId,
value: eventData.interaction.response
@hijonathan
hijonathan / example.html
Last active February 12, 2024 01:30
Generate a unique id in a Jinja template.
<!-- Jinja Unique ID Generator -->
{% macro random_int(len) -%}
{% for n in range(len) %}
{{ [0,1,2,3,4,5,6,7,8,9]|random }}
{% endfor %}
{%- endmacro %}
{% macro unique_id(count_groups=5, group_len=6, separator='-') -%}
{% set parts %}
@hijonathan
hijonathan / example-articles.json
Created February 8, 2016 16:24
Simple node script to import blog articles into HubSpot.
{
"count": "2",
"results": [{
"name": "Post 1",
"meta_description": "A post worth reading",
"meta_keywords": "articles, tests, things",
"post_body": "<h1>Hey!</h1>\n<p>Some words and stuff!</p>",
"blog_author_id": 40000001,
"publish_date": 1454948561,
"slug": "/one",
@hijonathan
hijonathan / example.html
Created September 30, 2015 02:24
Load Appcues asynchronously in a wrapped method.
<script>
(function(a, ns, cb) {
window[ns] = function(callback) {
(window[ns].q = window[ns].q || []).push(callback);
if (window[a] != null) {
while (window[ns].q.length) {
cb = window[ns].q.shift();
if (typeof cb === 'function') cb();
}
@hijonathan
hijonathan / snippet.html
Created August 10, 2015 18:35
Hide the Appcues "ok, got it" button.
<style>
.appcues-button.appcues-button-success {
display: none;
}
</style>
@hijonathan
hijonathan / readme.md
Last active September 16, 2019 11:43
Fun in-browser web scraper.

What is this?

This little script lets you easily define a few things you want from a web page (using CSS selectors), the crawl the site until you get them all.

It's based on the way Kimono works, but it's much simpler and has no limit to the number of results you can get. It also uses your auth tokens from the browser, so it's just as secure as your browser (which you should still be suspect of).

How do I use it?

Put that script into your browser terminal and run it. If you use Chrome, I highly recommend saving it as a snippet for easy reuse. To start scraping a site, create a Scraper instance with your desired options:

@hijonathan
hijonathan / readme.md
Created July 22, 2015 20:09
How to define explicit blocks of content for Appcues Hotspots.

The Situation

Modern frameworks like React use build tools like react-style that generate dynamic css. This is great for developers because it couples presentation and interactivity more closely. It can also be a better end-user experience for customers. However, it makes it impossible for Appcues' Hotspots to reliably find an anchoring element and therefore provide a great onboarding experience for new users.

A Solution

Instead of positioning itself relative to a specific element, like a button, a hotspot can align itself relative to an entire section, like a sidebar. This makes it possible for the hotspot to still appear next to the button, even if the button has a dynamic class, like .button-12z.

To define a region for Appcues, simply add an attribute to that element called appcues-region, and give it a unique value. Here's how it'd look in a standard layout:

@hijonathan
hijonathan / index.html
Last active August 29, 2015 14:23
Appcues + Meteor.js integration
<html>
<head></head>
<body>
{{#if currentUser}}
<script src="//fast.appcues.com/<your_appcues_id>.js"></script>
<script>
var user = {{currentUser}},
userId = user._id;
// Remove duplicate user id.
delete user._id;
@hijonathan
hijonathan / index.html
Last active August 29, 2015 14:23
Using Appcues on your marketing site.
<script src="//fast.appcues.com/<your_id>.js"></script>
<script>
(function(key, tid, parts) {
// Check if this user has already been identified before.
if (document.cookie.indexOf(key) > -1) {
parts = ("; " + document.cookie).split("; " + key + "=");
if (parts.length == 2) {
tid = parts.pop().split(";").shift();
}