Categories
Print

Setting up variables using trigger block

Setting variables / sending data to i-genie through the Trigger action block


Want to personalise chat or capture details about the visitor even before the chat is initiated? This is possible with i-genie where it allows its users to inject custom variables from outside using the Trigger action block even before the chat is initiated.


The values can be anything like sending and storing the details like name of the visitor, utm parameters of where the visitor is coming from can be captured and mapped with the variables.


The values stored in these defined variables, and can later be used at any given point of time in the flow of the chat.


There are two methods in i-genie that a user can follow to parse the information into variables. They are: 


  1. 1. Via Query Params
  2. 2. Injecting JSON in the code snippet



Via Query Params


Using this method, the user will be able to send Query Params on the domain in which the bot is hosted & the user will be able to map those params in the ‘Trigger’ action block with a variable name.


For example, www.i-genie.co.uk?utm_source=google&utm_medium=website


Let’s say I want to store the value of utm_source and utm_medium, I can simply map these names in the trigger action block and use the data wherever I want. Say, sending this data along with the contact details while creating a lead in your CRM.


The method will only be checked in the web channel


Users can click on “Add Another” to define more variables, however the maximum number of variables that i-genie allows users to map with the external data is 15



Injecting JSON in the code snippet

Using this method the user will be able to inject a JSON payload inside i-genie code snippet. And using the trigger action block the user will be able to map the object path with a variable.


For example, 

<script src="https://app.i-genie.io/chat-widget/tn8E5eTHuHhw145341765926vSqqHWVW.js" data-session-payload={"name": "Charles", "phone": "8164848686"} defer></script>


Here you see that in addition to the code snippet that you would have copied from the “Channel Configuration” page, we have the data-session-payload section. Adding this section with a JSON payload allows i-genie to read these values and store them in variables, which can be used inside the conversation flow.


In the above example, we have passed the values of “name” and “phone”, so now to store these values, we will map these fields on the Trigger action block.


It is essential to dynamically add this data-session-payload on i-genie code snippet before the code snippet is fired, because i-genie only reads this data once. 


To read the data again, visitors would have to refresh the page and start conversing with the bot again.