Using Talon.One from JavaScript

The official Talon.One JavaScript SDK can be found at https://github.com/talon-one/talon-one.js and supports all of the operations of our Integration API. The SDK is compatible with Node.js, and can be used in browsers with a module bundler such as Browserify or Webpack.

var TalonOne = require('talon-one')

var applicationId = 15025
var applicationKey = '41d3f05e76fd667b'

var client = new TalonOne.IntegrationClient('https://mycompany.talon.one', applicationId, applicationKey)

var customerId = 'id-used-by-my-company'

client.updateCustomerProfile(customerId, {
  // only include properties you want to update, null values are ignored
  name: 'Val Kust',
}, function (err, integrationState) {
  console.log(integrationState.profile)
  console.log(integrationState.event)
})

var sessionId = 'some-identifier-for-this-session'

client.updateCustomerSession(customerId, {
  // associate this session with the profile we created above
  profileId: profileId,
  // set the currency being used in this session
  currency: 'USD',
}, function (err, integrationState) {
  console.log(integrationState.profile)
  console.log(integrationState.session)
  console.log(integrationState.event)
})

client.trackEvent(sessionId, 'reached-goal', {
  goalId: 1234,
  goalName: 'Tweeted about My Company',
}, function (err, integrationState) {
  console.log(integrationState.profile)
  console.log(integrationState.session)
  console.log(integrationState.event)
})