Gathering detailed insights and metrics for @wix/site
Gathering detailed insights and metrics for @wix/site
Gathering detailed insights and metrics for @wix/site
Gathering detailed insights and metrics for @wix/site
npm install @wix/site
Typescript
Module System
Node Version
NPM Version
72.9
Supply Chain
95.6
Quality
89.3
Maintenance
100
Vulnerability
0
License
Total Downloads
5,925
Last Day
4
Last Week
71
Last Month
312
Last Year
5,925
Minified
Minified + Gzipped
Latest Version
1.21.0
Package Id
@wix/site@1.21.0
Unpacked Size
67.80 kB
Size
14.76 kB
File Count
58
NPM Version
6.14.11
Node Version
18.18.2
Published on
Jan 28, 2025
Cumulative downloads
Total Downloads
Last Day
-87.5%
4
Compared to previous day
Last Week
-48.6%
71
Compared to previous week
Last Month
-46.6%
312
Compared to previous month
Last Year
0%
5,925
Compared to previous year
The Site API enables code within Embedded Scripts and Site Widgets created with the CLI to interact with a Wix site. For example, you can access site data and interact with other Wix Apps, such as Wix Stores and Wix Bookings.
Note: This API is only available for use in Wix Apps that run within a Wix site environment. It isn't compatible with Velo code executed in the Wix Editor or on sites not hosted by Wix.
Install the @wix/site
package using npm or Yarn:
1npm install @wix/site
or
1yarn add @wix/site
Next, create a Wix Client with the relevant frontend modules. Supported modules are listed under Frontend Modules in the menu of this SDK reference. The following example uses the seo module:
1import { site } from "@wix/site"; 2import { createClient } from "@wix/sdk"; 3import { seo } from "@wix/site-seo"; // Frontend module of your choice 4 5const client = createClient({ 6 host: site.host({ applicationId: "<your_app_id>" }), 7 modules: { 8 seo, 9 }, 10});
Note: You can find your app ID in the OAuth page of the Wix Dev Center.
Finally, use the client
constant to interact with the site via the frontend module. For example:
1client.seo.title().then((title) => { 2 console.log("Site title:", title); 3});
You can create a Wix Client in one of your scripts inside your embedded html when you create an Embedded Script extension.
In your script, you can now create a Wix Client and use it to interact with the site. Creating the client differs based on the type
of the script:
type="module"
(ESM)When you create an Embedded Script extension, you provide an html snippet in which you can define script tags to load and execute Javascript. If you need to interact with Wix REST APIs or other Site APIs, you'll need to define a script tag that will have an access token injected into (only a single script tag can be used for this purpose).
Add the accesstoken="true"
attribute to the script tag to indicate that the script should be injected with an access token.
1<script accesstoken="true" src="<your script source>"></script>
In a script of type module
(ESM), the script should export a function called injectAccessTokenFunction
that will be called by Wix to inject the access token into the script. The function should be created by calling getAccessTokenInjector
on the auth
object of the Wix Client.
1import { site } from "@wix/site"; 2import { createClient } from "@wix/sdk"; 3import { seo } from "@wix/site-seo"; // Frontend module of your choice 4import { products } from '@wix/stores' // Any REST API module 5 6const wixClient = createClient({ 7 auth: site.auth(), 8 host: site.host({ applicationId: "<your_app_id>" }), 9 modules: { 10 seo, 11 products, 12 }, 13}); 14 15export const injectAccessTokenFunction = wixClient.auth.getAccessTokenInjector(); 16 17wixClient.products.queryProducts().find().then((productsResult) => { 18 console.log('Products => ', productsResult) 19}); 20 21client.seo.title().then((title) => { 22 console.log("Site title:", title); 23});
type="text/javascript"
(Classic)In a classic script (when no type
is specified or text/javacsript
is specified), you can create the Wix Client and use it directly in the script.
1import { site } from "@wix/site"; 2import { createClient } from "@wix/sdk"; 3import { seo } from "@wix/site-seo"; // Frontend module of your choice 4import { products } from '@wix/stores' // Any REST API module 5 6const wixClient = createClient({ 7 auth: site.auth(), 8 host: site.host({ applicationId: "<your_app_id>" }), 9 modules: { 10 seo, 11 products, 12 }); 13 14wixClient.products.queryProducts().find().then((productsResult) => { 15 console.log('Products => ', productsResult) 16}); 17 18client.seo.title().then((title) => { 19 console.log("Site title:", title); 20});
You can create a Wix Client in one of your custom elements when you create a Custom Element extension.
In a custom element, the custom element should expose an accessTokenListener
property which is a function that will be called by Wix to inject the access token into the custom element. The property should be set to the return of getAccessTokenInjector
on the auth
object of the Wix Client.
1import { site } from "@wix/site"; 2import { createClient } from "@wix/sdk"; 3import { seo } from "@wix/site-seo"; // Frontend module of your choice 4import { products } from "@wix/stores"; // Any REST API module 5 6const wixClient = createClient({ 7 auth: site.auth(), 8 host: site.host({ applicationId: "<your_app_id>" }), 9 modules: { 10 seo, 11 products, 12 }, 13}); 14 15class MyCustomEleemnt extends HTMLElement { 16 constructor() { 17 super(); 18 this.accessTokenListener = wixClient.auth.getAccessTokenInjector(); 19 } 20 connectedCallback() { 21 wixClient.products 22 .queryProducts() 23 .find() 24 .then((productsResult) => { 25 console.log("Products => ", productsResult); 26 }); 27 28 client.seo.title().then((title) => { 29 console.log("Site title:", title); 30 }); 31 } 32} 33customElements.define(tagName, MyCustomEleemnt);
No vulnerabilities found.
No security vulnerabilities found.