# How to create a Custom Widget

A **custom widget** is a pre-set piece of code that has been totally created with the custom widget creation flow. The generated code is hosted on our servers, but is not deployed on our platform. AB Tasty doesn’t own this piece of code, it only stores it for future purposes and usages: the client owns their development, deployment, sale, and maintenance. For more information about Custom Widgets (options, usage, parameters, examples, ...) please refer to the reference article about [**Custom Widgets**](https://docs.abtasty.com/~/revisions/qwC2vgJ0JzjAiTAzF6Mb/web-experimentation-and-personalization/editors-and-widget/list-of-widgets/custom-widget).

## How to create a custom widget <a href="#id-01gns5359jh68gw74rs7e8r0zr" id="id-01gns5359jh68gw74rs7e8r0zr"></a>

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-eea46bb3841cac0335dd3ad8d82f7fe2f2a4d421%2F1940316ed7bb5cb2561b9d7ca8eab070.png?alt=media)

From the [Widget library page](https://app2.abtasty.com/widget-library), click *Create a custom widget and* fill in the following information:

### **Main information** <a href="#h_01j87y3c7n143xt6xbssapev2y" id="h_01j87y3c7n143xt6xbssapev2y"></a>

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-f0ff7e4a218a6350df5c483801847bd4c9145b52%2F44ed1c73fd8e52aee6a7ea525903129e.png?alt=media)

* **Custom widget name:** give a clear name to easily understand what is inside and to retrieve it within the custom widget library. Each template must have a unique name, but not too long to be able to see it entirely. (E.g. “Pop-in news”).
* **Description (optional):** you can use this section to be more specific about the goal of the custom widget. (E.g. “To promote newsletter and collect emails - new branding”. This description will be also visible in the widget library in the editor and on the extended view in the widget library.
* **Label (optional):** the label is displayed on the widget card to enable you to sort them and use the filters. We’re providing a native list of labels such as ***Promotion but you can also create your own label by clicking on the drop-down***, typing your label, and clicking on ENTER. The new label will be visible in the future label choices.
* **Add image (optional):** the image is displayed on the widget card as a cover, it’s useful to identify your custom widgets in one look. You can upload your image or drag and drop it from your files.

### **Configuration** <a href="#h_01j87y5q0c498v2f6318hh5001" id="h_01j87y5q0c498v2f6318hh5001"></a>

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-94694ff81822063f090e61a32fc2f9ab46e0aa2e%2Fa57fa0991d65b665abb52ba96e7b8c19.png?alt=media)

* **JavaScript code section:** enter your JS snippet to inject your custom widget on your page.
* **CSS code section:** enter your CSS code to customize the UI of your custom widget.
* **HTML code section:** enter your additional HTML code to enrich your content.
* **Form code section:** declare your objects following the rules explained in the right panel. The objective is to create a specific form that will be usable in the visual editor when a user will add a custom widget to his campaign. This way, the user will be able to change parameters very easily. To get more information about the form structure, please refer to our [technical article](https://app.gitbook.com/s/dG0EHdNiO40UVA7Bz9mR/custom-widgets/widgets-getting-started). See also in the next paragraph more information about the the properties.
* **Assets section:** upload assets (images, video, sound) that will be automatically hosted on our server.

### **Configuration of the form**  <a href="#h_01j87y8cyr9gfnqm20x91jzjnx" id="h_01j87y8cyr9gfnqm20x91jzjnx"></a>

<figure><img src="https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-25a28379c0a598b913b0b1a7aea4d171d1fc32ab%2Fe2f89b0f9ed61adadd5665a689f41e66.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

***Defined properties to display forms:***

* **type:** Character string

Defines the type of form that will be displayed. Find the list of allowed types [***in this article***](https://app.gitbook.com/s/dG0EHdNiO40UVA7Bz9mR/custom-widgets/widgets-getting-started)

* **propName:** Character string

Key that will be used in the DATA object to get the value.

* **label:** character string or object

Defines the label of your form. It will be displayed to help the user understand the purpose of the form. It supports strings but also objects to translate into the following languages: English (en), French (fr), Spanish (sp), and German (de).

* **value:** Any\
  Form’s default value

Here is an example with a simple text input :

```
const buttonTextForm = {
   type: 'text',
   propName: 'buttonText',
   label: 'Button text',
   value: 'This is a simple text input',
};
```

For more information about all the capabilities of the custom form, please refer to this specific article: [**How to configure Custom Widgets Custom Forms**](https://docs.abtasty.com/~/revisions/qwC2vgJ0JzjAiTAzF6Mb/assets-library/widget-library/how-to-create-a-custom-widget/how-to-configure-custom-widgets-custom-forms)

## How to preview of a custom widget <a href="#h_01j87yfk828tpt7wm7785dd34s" id="h_01j87yfk828tpt7wm7785dd34s"></a>

Next to each code box, an eye appears on hover.\\

<figure><img src="https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-c5833c2361c351cd7dafcb2ad464f33044706032%2Fa64b0891ef2dd1e4682b519e23959158.png?alt=media" alt="" width="180"><figcaption></figcaption></figure>

Click on it to open a new tab and preview your code in a sandbox.

At this stage, we can’t open your website and simulate the custom widget on it. There are some chances that your custom widget is not executed if you have declared the presence of a certain element of your website’s structure which doesn’t exist in the sandbox. We’re currently working on another solution to avoid this problem.\
![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-4fb323e7c7645c27f9e79a9c3439c6d0ff618518%2Fde52746195faf7f0ce5710e898359571.png?alt=media)

**Good to know 💡**

You can also save your widget, add it in a campaign and work on a new version of your custom widget directly in the editor, as the preview will be automatic as your website will be loaded. There is an option to save your widget as the new one from the editor.

## How to save and use a custom widget <a href="#h_01j87ysjfdwk4wnkz6t3d683ge" id="h_01j87ysjfdwk4wnkz6t3d683ge"></a>

Click save on the bottom of the custom widget creation flow. The new widget will appear in the following list, section "Your widget" of the Widget library page.

You can directly click on "use" to create a new campaign that will contain the selected custom widget.

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-cc28fa24312917367bd69376bc9ed119b36a719d%2F4cecd76697a2e12ad8e106beb735147f.png?alt=media)

## How to use and edit a custom widget in the editor <a href="#h_01j87ynsk8dqkcqa6wqa7amakv" id="h_01j87ynsk8dqkcqa6wqa7amakv"></a>

By clicking on the 3 dots on the right bottom of each custom widget card, you can edit the custom widget.

Another method consists on adding the custom widget into a campaign and editing it directly in the visual editor, but the modifications will be local and the original custom widget template can’t be overwritten in the editor.

### **Form** <a href="#id-01gns5359kskqgj5mbs3avzv2q" id="id-01gns5359kskqgj5mbs3avzv2q"></a>

You can change CSS parameters (such as a color or wording) easily by editing specific fields. These fields have been configured on the custom widget set-up page. All pre-set-up fields are available in the form tab.

*Example: this is the form generated by the code created in the section "form" of the custom widget set-up page*

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-1ac857b3d4b676cc5948fd3b950230c94d599cd5%2Faf2ffc82634ce9d874c5e380a217868a.png?alt=media)

### **Code** <a href="#id-01gns5359kt9d85mt59yqdvknk" id="id-01gns5359kt9d85mt59yqdvknk"></a>

You can retrieve the code that has been configured in the custom widget template and to adapt it. You can change anything you want in the following code areas:\\

<figure><img src="https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-9899e9872d2e891d0a70e8502a642b9f0bd2d590%2F01c7cc42698557e412c63941561be22c.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

* Javascript
* CSS (e.g. changing a color)
* HTML (e.g. changing wording)
* Form

It can be useful to rework on your custom widget with the ability to see directly the effects on your changes in the editor (preview on your website) versus our preview option in the creation flow that executes the custom widget in a sandbox.

### **Assets** <a href="#id-01gns5359k045q550z66qn4zaf" id="id-01gns5359k045q550z66qn4zaf"></a>

This section **is not available** when you open your custom widget configurator for the first time.

You can see the number of assets added to the custom widget template next to the tab.

First, you must save your custom widget in the editor by clicking the *Save* button on the bottom right, and reopening the custom widget configurator from the history panel on the right of the editor.

Then, you will be able to access the Asset options and add some assets and/or delete the existing ones.

### **Saving your custom widget** <a href="#id-01gns5359k1bce7jpw2v75k9hs" id="id-01gns5359k1bce7jpw2v75k9hs"></a>

Once your rework is over, you have 2 possibilities to save your custom widget:

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fgit-blob-1f791e6bda545432c739a576554516615c0f54f3%2Fd617bee6bc795191774fd451157241c1.png?alt=media)

* **Save:** the custom widget will be applied to the campaign with all the changes you’ve done, **these changes are applied locally, in the campaign only.**
* Save as a new template: the custom widget will be applied to the campaign with all the changes you’ve done, **and a new custom widget will be created in your library.**

  All the changes are recorded in the new custom widget, except those which have been performed thanks to the form, which remain local for the widget used in the campaign.

The original custom widget template can’t be overwritten in the editor. This way, live campaigns using this custom widget can’t be compromised.

{% hint style="info" %}
**Good to know 💡**\
If you need to add several custom widgets to a variation, or to other variations/subtests, you won’t be able to duplicate them. You will have to use the variation duplication option, then do the needed changes in your second variation.
{% endhint %}
