Wix.Data.Public

Overview

Our SDK offers an easy way to store your app’s data – like text that a user customized.

Using Wix.Data.Public methods, you can store public data in the site’s HTML document.

This means that you may not need an external database for your app. How do you know if our solution is sufficient? Use these methods if:

  • Your app doesn’t need to store any sensitive information. Since the HTML document is public, make sure to only store information that’s displayed on the site.
  • Your app doesn’t need to store a lot of data (see the storage limitations below)

Wix.Data.Public methods are available in the Editor and Viewer only – not in the Dashboard.

Storing data

Each data entry is stored as a pair – a key and its value. Keys must be strings, and values can be strings, JSON objects, numbers, integers, and booleans.

Let’s use Wix Hit Counter as an example. This app is a small widget that counts the number of site visitors.

So what kind of data would you store for this app?

  • Strings – the layout/design used for the counter
  • JSON objects – animation settings or another group of related settings (you can store them as an object instead of storing each string separately)
  • Integers & numbers – starting number for the hit counter
  • Booleans – whether to count all visits to the site, or only new visitors

Setting the data’s scope

When you store data, you also define its scope as “app” or “component” – this determines where your data is available. By default, data is only available for the component that called the method, as well as that component’s settings. To make the data available globally for all app components, set the scope to app.

Storage limits

You can store a certain amount of data in each scope:

  • Component scope (per compId): 400 characters in total, for all data in this scope – including spaces
  • App scope (per app instance ID): 1,000 characters in total, for all data in this scope – including spaces
set

set(key, value, [options], onSuccess, [onFailure])

Stores a key with a value. If the key already exists, the previous value is overwritten with the new value. If the key doesn’t exist yet, it’s created now.

For example: In the Wix Hit Counter app, the counter starts at 1234 by default. When a user adds the app, you would store “startCounter” as the key, and “1234” as the key’s value. If a user changes it to 0, you would use the set method again to replace the value with “0”.

Parameters:

NameTypeDescription

Example:

remove

remove(key, [options], onSuccess, [onFailure])

Deletes the key. Future attempts to access this key will raise an exception until something is stored again for this key using the set method.

For example: Let’s say that Wix Hit Counter shows text after the number (“2,000 visitors”). Users can choose whether or not to show text (a boolean), and define the text to display. If the user chooses to just show the number, without any text after it, you can use remove to delete the “text” key.

Parameters:

NameTypeDescription

Example:

get

get(key, [options], onSuccess, [onFailure]) 

Returns the value for a given key.

 

For example, call this method when the iframe loads to display the app with the settings the user chose.

Parameters:

NameTypeDescription

Example:

Deprecated
  • Wix.Data.Public.getMulti – deprecated in SDK version 1.62.0

Was this page helpful?

What can we do to improve it?

What did you like about it?