# Integrate Optimizely with Talon.One
Create flexible and targeted promotional & loyalty campaigns with [Talon.One](https://www.talon.one/utm_source=optimizely&utm_medium=docs&utm_campaign=partners).
Campaigns can be created and managed by non-technical users such as Marketeers. There is no need to get your development team involved.
Promotions include:
1. Coupons
2. Gift Cards
3. Discounts
4. Loyalty
5. Referrals
6. Geo-fencing
7. Product Bundling
By integrating Optimizely with Talon.One you can create experiments that help your marketing team test promotional ideas, gain insights, make decisions based on facts that ultimately maximize ROI.
***NOTE**: [Optimizely full stack ](https://www.optimizely.com/platform/full-stack/) is required for this integration. Client-side implementations of [Talon.one](https://www.talon.one/utm_source=optimizely&utm_medium=docs&utm_campaign=partners) exposes you to risks of fraud. (e.g. a user changing an attribute relating to their profile via JS modification tools, which triggers them to receive a higher discount than they are entitled to) For more information please [read this](https://www.talon.one/developers/utm_source=optimizely&utm_medium=docs&utm_campaign=partners).*
## Set up the Optimizely for Talon.One integration
1. Login to your [Optimizely App](https://app.optimizely.com/)
2. Select `Create New Project` and select `Create Full Stack Project`
3. Give it an appropriate name and description
4. In the `experiments` tab select `Create New` and `A/B test`
5. Add an appropriate `Experiment Key` and `Description`
6. Add an appropriate `Variation Keys`, `Descriptions` and `Traffic Distribution`<br />An example campaign, compare **Buy 2 and get an additional free product** vs **Buy 3 and get the cheapest product for free**

8. Update the variables in the following boiler plate code:
```
var variation = optimizelyClientInstance.activate('promotion', userId);
if (variation === 'variation_a') {
customerSession.attributes.promotion = "variation_a"
} else if (variation === 'variation_b') {
customerSession.attributes.promotion = "variation_b"
} else {
customerSession.attributes.promotion = ""
}
```
*The boiler plate code appends an attribute to the [Talon.one Customer Session](https://developers.talon.one/Integration-API/API-Reference#updateCustomerSession). The attribute signifies which variation Optimisely has assigned the user to. The [attribute must be set up in Talon.one](https://help.talon.one/hc/en-us/articles/360010028740-Creating-Attributes/utm_source=optimizely&utm_medium=docs&utm_campaign=partners) so that it is recognised and your team can create promotions based on this attribute. Example campaign in the next section. This code is in JavaScript but the same principle can be applied using an appropriate [Talon.One SDK](https://developers.talon.one/SDKs/Overview/utm_source=optimizely&utm_medium=docs&utm_campaign=partners)* <br />
9. To track an event such as `session closed` which is an event that takes place when the user confirms the completetion of thier order, the following boilerplate code is needed:
```
optimizelyClientInstance.track('session_closed', userId);
```
10. Press `run` on development environment
## Set up Talon.One for Optimizely integration
1. Create a `session attribute` that was added to the customer session. It is highly recommended to create a `suggestion` for each variant. This will allow users to select each variant from a dropdown.<br />

3. Navigate to the rule builder. Build campaigns using the attribute and distinguish the traffic via each variant.
For Example:
### Buy 2 and get an additional free product
* Use the c`art item filter` to count the number of items in the cart.

* Check for variation A and that the count has at least 2 items in the cart. If true, use the effect `add item to cart` and enter the SKU of the free item

### Buy 3 and get the cheapest product for free
* Create an additional `cart item filter` to establish the cheapest item

* this time check for variation_b and that the cart count = 3. Then set an item discount, of the value of the cheapest item

### Bonus
To maximize the effectiveness of the promotion, create a notification to alert users of the promotion, but haven't filled the criteria yet. For example:
If the product count is less than 2, display message that if they purchase 2 products they will get a free item. Dymamic values can be used in this messaging e.g. "add 1 more item" if one is already added.
