> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Embedded Spaces

If you'd like to run your Messaging campaign in your own website, app, or other location, you may create a campaign with embedded messages.

## Prerequisites

Running a Messaging campaign in an embedded space requires an API key from MX. If you didn't obtain one during the onboarding process, contact [Support](https://support.mx.com/).

## Create a New Embedded Message

Use the dashboard to add, edit, or delete a space and track performance of an embedded message. To create a campaign for an embedded space, use the Messaging feature's [creation wizard](/products/data/marketing-hub/messaging-feature). Note the settings you'll need for creating an embedded message:

* Select Embedded for the Delivery setting
* Select the message space for display
  * Select a previously-created space
  * Create a new space
* Set the Message type
  * Banner ad
* Follow the steps to set priority, add the content and link, and launch the campaign
* Copy the space code

## Use the Space Code

Embedded space code is in HTML and JavaScript (see example). The campaign message can be loaded in any location able to access the user's MX `user_id`.

* If a Message is located in multiple places, you will need to maintain the same dimensions across locations.
* If a user is targeted for multiple campaigns, they will be displayed according to the priority set when creating the campaign.

## Example Code

```html theme={null}
<!-- This script loads the MDAnalytics functionality -->
  <script
    type="text/javascript"
    src="https://analytics.moneydesktop.com/analytics.v1.js">
  </script>

<!-- This element is where the banner is injected -->
  <div id="targetedMXAd" style="text-align: center;" />


<!-- This script requests the ad for the user from MX -->
<script type="text/javascript">
  (function () {
    function load() {
      MDAnalytics.loadBanner({
        analytics_api_key: "IssuedByMX",
        user_id: "userIdFromRealTimeAPI",
        element_id: "targetedMXAd",
        default_banner_image_url: "urlOfDefaultImageToLoad",
        default_banner_url: "urlOfDefaultClickDestination",
        campaign_group_guid: "embeddedSpaceGuidFromDashboard",
      });
    }

    if (document.readyState === "loading") {
      document.addEventListener("DOMContentLoaded", load);
    } else {
      load();
    }
  })();
</script>

```

### Target Fields

| Field name                 | Requirement | Description                                                                                                          |
| -------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------- |
| `analytics_api_key`        | Required    | Unique API key that authenticates the request on the MX Platform.                                                    |
| `campaign_group_guid`      | Required    | Unique identifier of the campaign space or group that the banner belongs to.                                         |
| `user_id`                  | Required    | Unique ID that identifies the user. This value is created during user creation using MX APIs.                        |
| `element_id`               | Required    | Unique ID for a placeholder HTML element that will be replaced with the ad when loaded.                              |
| `default_banner_image_url` | Optional    | The URL of the image banner ad that's loaded when no campaign is available to load.                                  |
| `default_banner_url`       | Optional    | The destination URL that a user is directed to when they select the banner ad when no campaign is available to load. |
