For an overview of how the Chameleon API works, please first read this article.

Syncing user and company data to Chameleon account can be helpful for: 

  • Targeting users with tours based on who they are.
  • Personalizing content within tours (merge tags in content).
  • Better URL matching (merge tags in URLs).

Via JavaScript API

Users need to be identified with a unique ID (UID) to enable them to see tours. We also strongly recommend sending email to maintain a user's identity across Chameleon and any integrations you enable.

Use the chmln.identify method, calling this as soon as the user is identifiable on page load. 

(Note: These are example scripts, don't forget to change the PLACEHOLDERS. )

chmln.identify(USER.ID_IN_DB, { // Unique ID in your database
  email: USER.EMAIL,
  // Add other pertinent parameters here
});

You can also send other attributes associated with a user in the same manner. 

This includes any company (group) associated with the user, and related company attributes. For this to sync across your integrations, please ensure the unique company identifier (company UID) is the same as within your system.  

(Note: Please confirm the attributes to be sent with your project owner.)

chmln.identify(USER.ID_IN_DB, {      // Unique ID in your database (e.g. 23443 or "590b80e5f433ea81b96c9bf6")
  email: USER.EMAIL,                // Put quotes around text strings (e.g. "jim@example.com")
  created: USER.SIGN_UP_DATE,       // Send dates in ISO or unix timestamp format (e.g. "2017-07-01T03:21:10Z" or 1431432000)
  name: USER.NAME,                  // We will parse this to extra first and last names (e.g. "James Doe")
  role: USER.ROLE,                  // Send properties useful for targeting types of users (e.g. "Admin")
  logins: USER.LOGIN_COUNT,         // Send any data about user engagement (e.g. 39)
  ...
  project: USER.PROJECT_ID,         // Send any unique data for a user that might appear in any page URLs (e.g. 09876 or "12a34b56")

  company: {                        // For B2B products, send company / account information here
    uid: COMPANY.ID_IN_DB,          // Unique ID of the company / account in your database (e.g. 9832 or "590b80e5f433ea81b96c9bf7")
    created: COMPANY.SIGN_UP_DATE,  // To enable targeting all users based on this company property
    name: COMPANY.NAME,             // Send any data that appears within URLs, such as subdomains (e.g. "airbnb")
    trial_ends: COMPANY.TRIAL_ENDS, // Send data about key milestones (e.g. "2017-08-01T03:21:10Z")
    version: COMPANY.VERSION,       // If your software varies by version then this will help show the correct guidance (e.g. "1.56")
    plan: COMPANY.PLAN,             // Send null when no value exists (e.g. "Gold", "Advanced")
    ...
    spend: COMPANY.CLV              // Send other properties that will help in targeting users (e.g. sales rep, source, stage)
  },
});

Via Rest API

Create a user profile

Send a POST  to https://observe.trychameleon.com/profiles
Include a UID  that uniquely identifies the user in your database (required)
Include an email  to connect their data in integrations you enable (recommended)
Include any and all parameters pertinent to the user (optional)

Example: Create a user with uid=123  on your "Standard"  plan.
Request:

curl -X POST -H "X-Account-Token: SECRET" -d '{"uid":"123","email":"john@example.com","plan":"Standard"}' https://observe.trychameleon.com/profiles

Response:

{
  profile: {
    id: "590b80e5f433ea81b96c9bf6",
    uid: "123",
    plan: "Standard",
    ...
  }
}

Update a user profile

Send a PATCH  or PUT  to https://observe.trychameleon.com/profile
Include the same information as "Create"

Example: Update a user with uid=123  to your "Advanced"  plan.
Request:

curl -X PATCH -H "X-Account-Token: SECRET" -d '{"uid":"123","plan":"Advanced"}' https://observe.trychameleon.com/profile

Response:

{
  profile: {
    id: "590b80e5f433ea81b96c9bf6",
    uid: "123",
    plan: "Advanced",
    ...
  }
}

Seeing existing user properties

To view the user properties associated with the current user, you can use the following command within the JS console:

chmln.data.profile.attributes

To see all the user properties currently being sent, you can run some code in your local browser. Open the JavaScript console, under Developer Tools and paste the following code and hit Enter:

chmln.data.segment_properties.where({kind: 'profile', source: 'chmln'}).map(function(p) { return p.get('prop') })

Here are some more examples of what you might send. More available on our Github

  // Add the snippet here with account id (i.e. '<%= ENV['CHAMELEON_ACCOUNT_TOKEN'] %>')
  // Assuming you have exposed `helper_method :current_user` in your `ApplicationController`
  <% if current_user.present? %>
      chmln.identify({
          uid: '<%= current_user.id %>',
          created: '<%= current_user.created_at.iso8601 %>',
          email: '<%= current_user.email %>',
          plan: '<%= current_user.account.plan_name %>',
          spend: '<%= current_user.account.plan_cost %>'
      });
  <% end %>
Ruby
Copy
// Add the snippet here with account id (i.e. config.chameleonAccountId)
// Assuming you preload your page with a current user(function() {
  if(currentUser.id) {
    chmln.identify({
      uid: currentUser.id,
      created: currentUser.createdAt,
      email: currentUser.email,
      plan: currentUser.planName,
      spend: currentUser.planCost
    });
  }
})();JavaScript
Copy
// Add the snippet here with account id (i.e. config.chameleonAccountId)
// Assuming you call `currentUserLoaded` after fetching the user(function() {
  var currentUserLoaded = function(currentUser) {
    chmln.identify({
      uid: currentUser.id,
      created: currentUser.createdAt,
      email: currentUser.email,
      plan: currentUser.planName,
      spend: currentUser.planCost
    });
  };  var xhr = $.get('/user.json');
  xhr.done(function(data) {
    // Setup other aspects of the environment    currentUserLoaded(data.user);
  });
})();JavaScript
Copy
  // Add the snippet here with account id (i.e. <?php echo $GLOBALS['chameleonAccountId'] ?>)
  // Assuming your page has loaded the current user as the object $current_user
  <?php if (var_dump((bool) $current_user->present)): ?>
    chmln.identify({
      uid: '<?php echo $current_user->id ?>',
      created: '<?php echo $current_user->created_at ?>',
      email: '<?php echo $current_user->email ?>',
      plan: '<?php echo $current_user->account->plan_name ?>',
      spend: '<?php echo $current_user->account->plan_cost ?>'
    });
  <?php endif; ?>
PHP
Copy

Timestamps

Chameleon will interpret a property as a timestamp for a few reasons:

  1. If the timestamp is ISO 8601 standard, Chameleon will always assume the value is a timestamp.
  2. If the timestamp is a Unix Timestamp that falls between 1973 and 2033 and the name is either 'created', or ends in '_at' or '_time'. 

Chameleon will interpret any of these properties as a timestamps: {started: \"2016-09-05T15:45:39+00:00\", ended: \"2016-09-05T15:45:39Z\", created: 1472985601, started_at: 1095292800, ended_at: 1095352800}.

Default properties

From the JavaScript code snippet, we collect a set of default properties that cannot be overridden, they are browser_x, browser_n and browser_tz. In addition our servers add browser_l , last_seen_session_count , last_seen_at , and last_last_seen_at which cannot be permanently overridden.

Reserved Keywords

Chameleon has some reserved keywords that are not passable in identify. They include: id, user_id, account_id , profile_id, created_at, updated_at, options, at , now , disabled, chameleon_admin and percent .

Did this answer your question?