Code scripts let you execute custom functionality from within Chameleon Experiences. This means you can do things like focusing the cursor in a specific field, changing user settings or data, simulating multi-element clicks, or launching other Experiences using APIs. 

Availability & Usage

🔐 Available for all plans

🔓 Exception needed for Content Security Policy cases

📍 Ready to use in Tours Microsurveys Launchers

Quick access

Where to use

There are a few places you can leverage code scripts within Chameleon: as an Item within a Launcher, or as an Additional Action to a button. In these instances, the code you add will run when that Launcher Item or Step Button is clicked. You can also use custom code in your Tour body to display custom content.

1.  Launcher Items

Chameleon Launchers have the ability to include "Code scripts" as an Item, alongside URLs, Chameleon Tours, and Chameleon Microsurveys. This means you can run some custom code when a user clicks on a Launcher item.

Your Launchers can be the single consolidated widget for your site, and you can open other widgets or take other actions from the Chameleon Launcher. 

2. Step buttons

You can also run custom JS code as a button action, from any button within a Chameleon Tour, Tooltip, or Microsurvey. This provides the flexibility to trigger a custom Experience from a CTA within a Chameleon Experience. 

Another powerful use case is firing clicks on multiple elements and mimicking sequenced button clicks. With some Tours, there may be multiple clicks required to take your users to the right place, and the next Step. This would be the case where you have different subpages, or tabs with different input fields, that would require specific guidance.

3. Tour body

You can leverage HTML code within the body component of your product Tours to display unique content and create more interactive guidance.

You'll first have to enable the toggle from the Dashboard, and then you can go in and add your code when building out your Tour.

💡Ensure your code is on a single line when pasting it into the body.

Example templates

Below are some examples of code scripts that you could include. If you want to just try this out, you can use alert("hello world!") as a script and see the JS alert appear. 

Open third-party chat or message widget

You may not want to show a chat widget for all users or may want to restrict how easily a user can start messaging your support team, so you can add this as an item within your Chameleon Launcher.

This means the user will first see your list of (hopefully relevant) items and then any options to start a chat. 


Using Zendesk's Chat API you can open a chat window if not already open using the following command: 

zE('webWidget', 'chat:send', message<string>); 

You can also initiate other actions alongside the above, such as:

  • Registering a callback when the chat is started or ended

  • Open the chat window in a new tab or window

👉 Explore the Zendesk Chat API


You can open up Intercom Messenger by running the following:


This will open the Messenger window with the message list. You can also:

  • Open Messenger with the last message open

  • Open Messenger and initiate a new message

👉 Read more about the Intercom Messenger JS API

Help Scout

Help Scout is another popular support ticket solution, and you can open up their Beacon messaging widget by calling:


Other actions you can take include:

  • Search Help Scout Docs articles and load the results screen

  • Suggest articles based upon the page URL (and other factors)


Hubspot is a marketing automation platform that includes emails, CRM, and live chat. You can open the Hubspot live chat widget by calling:;

👉 Discover what else you can do with Hubspot's Conversations Live Chat widget API


Show the Olark chat widget by using the expand  method from their JavaScript API:



Pop open a Drift chat window from a Launcher by running this call:


You can also:

👉 Read more about the Drift API 


Launch the Freshdesk chat widget with the following API call:


👉 Discover more about Freshdesk widget actions

Mimic multi-element clicks

To simulate multi-element clicks when launching Tours, you can use the 'Run Custom Code' Additional Action from any primary or secondary button. This makes use of the HTML Element click method to simulate mouse clicks on different elements.

You can run several commands in a sequence that would mimic a user clicking those elements in your product. To achieve this, you'll have to create a function for each user click, then specify the selector, and add a call for that action.

Also, you'll want to include a time-out for secondary and onward actions, to ensure those elements will be found.

🧑‍💻 Engineer can help: The examples below are based on specific page structures, but your engineer can help adjust the code to fit your specific element layout.


  • Launching a Tour Step from a slideout sub-page

    In this example, the Tour Step appears after a user opens a "Profile" slideout from a homepage icon (the 2nd in a row), clicks on the 1st page on it - "Settings", clicks on a 2nd page -"My data" and selects the third tab in it "Plan"

function clickOne() { document.querySelector("#profile-link").click(); };

function clickTwo() { document.querySelector("#modal-root > div > div.side-drawer > div > div.primary-content > div:nth-child(2)").click(); };

function clickThree() { document.querySelector("#modal-root > div > div.side-drawer > div > div.primary-content > div > > a:nth-child(1)").click(); };

function clickFour() { document.querySelector("#modal-root > div > div.side-drawer.entered > div > div.primary-content > div > div:nth-child(2) > nav > div > a:nth-child(3)").click(); };

setTimeout(clickTwo, 50);
setTimeout(clickThree, 100);
setTimeout(clickFour, 500);

  • Launching a Tour Step after an input field selection on a sub-page

In this example, the Tour Step appears after a user opens a "Profile" page from a homepage icon (4th in a row), clicks on the 3rd tab in a section - "Settings", and selects "My data", the 2nd option from a dropdown list.

function clickOne() { document.querySelector("#profile-link").click(); };

function clickTwo() { document.querySelector("#div-root > div > div.class > div > div.primary-content > div:nth-child(3)").click(); };

function clickThree() { document.querySelector("#div-root > div > div.class > div > button >.click(); };

function clickFour() { document.querySelector("#div-root > div > div.span > div > div:nth-child(2).click(); };

setTimeout(clickTwo, 50);
setTimeout(clickThree, 100);
setTimeout(clickFour, 500);

🎯 Please note, that if you change the HTML structure of your pages your code may need to be tested to ensure it still works.

Launch third-party Microsurvey or form

Chameleon Microsurveys are great for continuous feedback and quick questions, but if you'd like to use a longer Microsurvey or hook into your existing NPS collection tool, then you can do that from the Launcher too! 


You can use the Typeform API to configure a particular Microsurvey to show / open when the user clicks the Code Script item in your Chameleon Launcher. 

Using pop-up mode might make the most sense, but a variety of delivery modes are available in the docs here.

createPopup('<form-id>', options)

Other actions

Update user data

You may want to add a particular attribute to a user (e.g. add a tag that they are interested in a new feature, or enroll them into a beta program, etc.) or update data about that user in one of your other systems. Read how you can do this here.

Hide the Launcher

Although clicking outside the Launcher will close the Menu, you can also close the Menu using the show  API as described here.

Opt that user out of all Chameleon Experiences

You can let a user opt-out of all in-product Experiences built with Chameleon. To do this, run the following script (either from an item in the Launcher or a button in a Tour Step): 

chmln.identify('uid'), { 
 disabled: true

👉 You can do so much more with our API! Explore what's possible.

Find out more

Did this answer your question?