Segment.io's Analytics.js Track: Pass an Object?

Is it possible to pass an object to the .track() method of analytics.js?

analytics.track('button clicked', {
  prop1: 'val1',
  // object e.g. {prop2: 'val2', prop3: 'val3'}
});

I looked through their documentations and source code, but couldn't find an answer. I would greatly appreciate your help if you've had experience with this and have an answer.

Answers


Yes, you can pass a dictionary of properties for the track call. Here's an example:

analytics.track({
  event: 'Product Added',
  properties: {
    name: 'Ron Livingston',
    industry: 'Technology',
    value: 5
  }
});

If you want to know if you can call track like this...

analytics.track('event', { 
 prop1: 'blah', 
 objProp: { 
   thing1: 'yes', 
   thing2: 'no' 
}

...the answer is yes. However, it won't show up nicely in all of the integrations because the end tools don't accept object properties. The only one that I'm sure it will work with is Amplitude because they'll flatten the objects into dot notation.


Need Your Help

Mongodb query - and condition

javascript node.js mongodb

I did this query http://server/usuarios?query={"senha":"1234"} and works fine: it lists all usuarios with senha: 1234

Is it possible to enter a text in a textbox without specific Element ID

java selenium selenium-webdriver browser-automation

Im doing a test that enter text in the textbox but it dont have specific ID so everytime i run the test it will change. im using selenium webdriver in java please help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.