Skip to content

Instantly share code, notes, and snippets.

View gooley's full-sized avatar

Christopher Gooley gooley

  • Microsoft Research - Health Futures
  • Seattle
  • 10:11 (UTC -07:00)
View GitHub Profile
@gooley
gooley / mixpanel.js
Created October 9, 2014 19:14
Mixpanel + Preact example
// A standard mixpanel track event takes a name and optional Properties
mixpanel.track("Viewed Dashboard", {"Gender": "Male", "Age": 21});
// Pass account context information along with each Track call using the following properties
{
"_account_id": "333434", // this should be your internal id for the account
"_account_name": "Snapchat" // this should be a display name for the account
}
// pass those properties (along with any others you already pass) with each track call
@gooley
gooley / segment.cs
Created September 29, 2014 19:04
Segment.io Server Side example - .NET
private static void LogAction(string username, string action, string item = "None", Segmentio.Model.Properties properties = null)
{
// Segment.IO Properties
if (properties == null)
{
properties = new Segmentio.Model.Properties();
}
properties.Add("ProductName", "Example WebApp");
properties.Add("URL", "http://www.example.com");
@gooley
gooley / zendesk.html
Last active August 29, 2015 14:06
Zendesk Helpcenter Instrumentation
// document head
// Put this script block inside the template for your document head, it will load and initialize the Preact logging javascript
<script>
window._preactq = window._preactq || [];
window._preactq.push(['_setCode', 'your_project_code']);
$(function(){
if(HelpCenter.user){
window._preactq.push(['_setPersonData', {
name: HelpCenter.user.name,
@gooley
gooley / preact.html
Last active August 29, 2015 14:06
preact-wootric-example.js
<script type="text/javascript">
var _preactq = _preactq || []
// TODO: put your preact project code here
_preactq.push(['_setCode', 'your-code-1234' ]);
// TODO: insert the info for the currently logged-in user
_preactq.push(['_setPersonData', { email: 'john@doe.net', name: 'John Doe', created_at: 1410817680 } ]);
// TODO: insert the account info for the currently logged-in user
_preactq.push(['_setAccount', { id: '12334', name: 'Doe Flower Shop' }]);
(function() {
@gooley
gooley / preact-wootric-example-erb.js
Created August 7, 2014 22:59
Preact + Wootric installation (Ruby/ERB specific)
<script type="text/javascript">
var _preactq = _preactq || []
_preactq.push(['_setCode', <%= Preact.configuration.code.to_json %>);
_preactq.push(['_setPersonData', <%= @current_user.to_preact.to_json %>]);
_preactq.push(['_setAccount', <%= @current_project.to_preact.to_json %>]); // TODO: replace @current_project with variable for the "account" model
(function() {
var preact = document.createElement('script'); preact.type = 'text/javascript'; preact.async = true;
preact.src = 'https://s3.amazonaws.com/lessneglect-cdn-01/js/preact-4.0.js';
@gooley
gooley / preact-wootric-example-haml.js
Last active August 29, 2015 14:05
Preact + Wootric installation (Ruby/HAML specific)
<script type="text/javascript">
var _preactq = _preactq || []
_preactq.push(['_setCode', #{ Preact.configuration.code.to_json }]);
_preactq.push(['_setPersonData', #{ @current_user.to_preact.to_json }]);
_preactq.push(['_setAccount', #{ @current_project.to_preact.to_json }]); // TODO: replace @current_project with variable for the "account" model
(function() {
var preact = document.createElement('script'); preact.type = 'text/javascript'; preact.async = true;
preact.src = 'https://s3.amazonaws.com/lessneglect-cdn-01/js/preact-4.0.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(preact, s);
@gooley
gooley / example
Last active August 29, 2015 14:03
Backfill Example - Data Formats
// User Event
{
"person": {
"email": "gooley@adobe.com",
"name": "Christopher Gooley",
"created_at": 1404329291.5481384,
"uid": "383838211"
}
"event": {
@gooley
gooley / preact.js
Last active August 29, 2015 14:03
Preact+Segment Client-Side Example
// current_user is your logged-in user object
// current_account is your account object
analytics.identify(current_user.id, {
email : current_user.email,
name : current_user.name
});
analytics.group(current_account.id, {
name: current_account.name,
@gooley
gooley / track.rb
Last active August 29, 2015 14:03
Preact+Segment Server-Side Example
# @current_user is your logged-in user object
# @current_account is your account object
Analytics.track(
user_id: @current_user.id.to_s,
event: name,
properties: {
account: {
name: @current_account.name,
id: @current_account.id.to_s,
@gooley
gooley / push_ducksboard.rb
Last active December 20, 2015 20:19
Rough example of how to push data into Ducksboard from the Preact API. We run something like this every hour to keep our Ducksboard dashboard up to date. Put in your api_key and secret from https://secure.preact.io/settings/api. For each of the push_duck calls, you pass in the ID from the widget edit page (e.g. 140456 from this screen http://cl.…
def update_ducksboard
api_key = ""
api_secret = ""
url = "https://#{api_key}:#{api_secret}@api.preact.io/api/v2/insights/health"
data = RestClient.get "#{url}", :content_type => :json, :accept => :json
accounts = data["accounts"]
# boxes
push_duck("YOUR_DATAPOINT_ID", accounts["good"]) # good account health