Skip to content

Instantly share code, notes, and snippets.

@gooley
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save gooley/efbb809a83394932afea to your computer and use it in GitHub Desktop.

Select an option

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

gooley commented Jul 1, 2014

Copy link
Copy Markdown
Author

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

hutchike commented Jul 2, 2014

Copy link
Copy Markdown

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