DOCS

Messages element

/

Messages element

Learn how to display custom messages to your international shoppers depending on their location.

The Messages element allows you to display custom messages to your international shoppers depending on their location. You can use the Messages element to display messages like:

  • Whether or not you ship to specific countries
  • Promotions for specific countries
  • Information about shipping and duties

The Messages element pulls content from custom messages you have set up on your account and can be inserted anywhere on your site where you want to display a message.

Zonos Messages element example

1

Import the Zonos SDK

React
Vanilla JavaScript

First, install the Zonos Elements package in your React project. This will automatically add the Zonos SDK as a peer dependency, and includes TypeScript typings out of the box for a better developer experience.

Terminal

1
npm install --save @zonos/zonos-elements-react
2

Configure the Zonos SDK

React
Vanilla JavaScript

Once the Zonos Elements package is installed, you can configure the Zonos SDK in your React project. You need to have a Zonos account and API key to use Elements on your site.

The Elements React library exposes a ZonosProvider component that you can use to configure the Zonos SDK. You can wrap your entire application in the ZonosProvider component, or you can wrap only the components that use the Zonos SDK. We recommend storing your Zonos API key in an environment variable and passing it to the ZonosProvider component as a prop for security reasons.

App.js

1
2
3
4
5
6
7
import { ZonosProvider } from '@zonos/zonos-elements-react';

export const App = () => (
  <ZonosProvider config={{ apiKey: process.env.REACT_APP_ZONOS_API_KEY }}>
    {/* The rest of app goes here */}
  </ZonosProvider>
);
3

Create a Messages element

React
Vanilla JavaScript

To create a Messages element, use the Messages component from the Zonos Elements React library. When the Messages component renders, it will automatically pull in the messages you have set up on your account and display them to the shopper depending on their location.

JavaScript

1
2
3
4
5
6
7
8
9
import { Messages } from '@zonos/zonos-elements-react';

export const YourComponent = () => (
  <div>
    {/* The rest of your component goes here */}
    <Messages />
    {/* The rest of your component goes here */}
  </div>
);

Zonos Messages element example

Was this page helpful?


© 2023 Zonoszonos.com