Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gooley
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gooley/efbb809a83394932afea to your computer and use it in GitHub Desktop.
Save gooley/efbb809a83394932afea to your computer and use it in GitHub Desktop.
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,
license_mrr: @current_account.monthly_rate.to_i, # optional
license_status: @current_account.status # optional
}
},
context: {
traits: {
email: @current_user.email,
name: @current_user.name,
created_at: @current_user.created_at.to_i
}
})
# example with hard-coded values
Analytics.track(
user_id: "123",
event: "deleted-thing",
properties: {
account: {
id: "55534",
name: "Preact",
license_status: "paying", # optional
license_mrr: 499 # optional
}
},
context: {
traits: {
email: "gooley@preact.com",
name: "Christopher Gooley",
created_at: 383904000
}
})
@gooley
Copy link
Author

gooley commented Jul 1, 2014

The Account data is sent as part of the Event Properties section (because events are associated with accounts directly).

The Person data is sent as part of the Context Traits (because these are tied to the person directly)

@hutchike
Copy link

hutchike commented Jul 2, 2014

Thanks. That's useful. I suggest posting it on your website because it would definitely save your future customers a lot of development time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment