# Cordova

## SDK token

To get SDK token go to app settings page and copy SDK token:

<figure><img src="https://1024951375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj3mk8X1lr8iYBWypC-%2Fuploads%2Fwhqu7b4N5IqVctVzE7ej%2FScreenshot%202024-10-30%20at%2010.35.21.png?alt=media&#x26;token=11b02d07-af65-478e-b247-ebc49f661f03" alt=""><figcaption></figcaption></figure>

Go to Settings, Setup section.&#x20;

<figure><img src="https://1024951375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj3mk8X1lr8iYBWypC-%2Fuploads%2FwQDIZgSt1etQyRWrgjQh%2FScreenshot%202024-10-30%20at%2010.44.35.png?alt=media&#x26;token=615eded2-78d5-4a16-aae9-33102c60dc2a" alt=""><figcaption></figcaption></figure>

## Setup

Choose Custom solution and copy the code. Add the following code to the **`<head>`** section of your HTML page to include the necessary script and styles.

```html
<script src="https://cdn.jsdelivr.net/npm/@storysdk/core@latest/dist/bundle.umd.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@storysdk/core@latest/dist/bundle.css">
```

Add an HTML element to the page and place the SDK token in the **`data-storysdk-token`** attribute.

<pre class="language-html"><code class="lang-html">&#x3C;!DOCTYPE html>
&#x3C;html lang="en">
&#x3C;head>
    &#x3C;meta charset="UTF-8">
    &#x3C;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &#x3C;title>Your Page Title&#x3C;/title>
    &#x3C;script src="https://cdn.jsdelivr.net/npm/@storysdk/core@latest/dist/bundle.umd.js">&#x3C;/script>
<strong>    &#x3C;link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/@storysdk/core@latest/dist/bundle.css">
</strong>&#x3C;/head>
&#x3C;body>

    &#x3C;!-- Place your HTML element with SDK token here -->
    &#x3C;div id="storysdk" data-storysdk-token="YOUR_SDK_TOKEN">&#x3C;/div>

    &#x3C;!-- Other content on your page -->

&#x3C;/body>
&#x3C;/html>

</code></pre>

Make sure that the Content-Security-Policy allows requests to <https://api.storysdk.com> and Google servers for analytics tracking. For example, add the following code to the **`<head>`** section:

```html
 <meta 
  http-equiv="Content-Security-Policy" 
  content="
    default-src 'self';
    script-src 'self' https://www.googletagmanager.com;
    connect-src 'self' https://www.google-analytics.com https://www.googletagmanager.com https://api.storysdk.com;
  ">
```

Enable Background Modes in Xcode (for iOS)

1. **Open Your Project in Xcode**
   * Navigate to your app in Xcode and select your app target from the project navigator.
2. **Add Background Modes**
   * Go to the **Signing & Capabilities** tab.
3. **Configure Background Modes**
   * Click the "+ Capability" button and select "Background Modes".
   * Check the "Audio, AirPlay, and Picture in Picture" option

<figure><img src="https://1024951375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj3mk8X1lr8iYBWypC-%2Fuploads%2Ff0wwh8tWgWQZ0CHD9Kqx%2Fimage.png?alt=media&#x26;token=abd9edf3-0347-4428-82b3-078f7d86c741" alt=""><figcaption></figcaption></figure>

Run the application build and test the stories in the simulator.

<figure><img src="https://1024951375-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mj3mk8X1lr8iYBWypC-%2Fuploads%2F4K42hkEm1CwYbRSedrpd%2FIMG_6570.PNG?alt=media&#x26;token=49e600d4-b87f-405e-946e-3f084d65bcf2" alt=""><figcaption></figcaption></figure>

⚡️ For the interface elements to work correctly, you need to add the following parameters to the config.xml file in the Cordova project

```xml
<preference name="AllowInlineMediaPlayback" value="true" />
<platform name="ios">
    <config-file parent="UIBackgroundModes" target="*-Info.plist">
        <array>
            <string>audio</string>
        </array>
    </config-file>
</platform>
```

<mark style="background-color:purple;">⚡️ Please note that in order for stories to be displayed in the SDK, they need to be published.</mark>

## Customisation

By specifying the following data attributes in the HTML tag, you can control the appearance, behavior, and functionality of the SDK directly from HTML without additional JavaScript configuration.

* **`data-storysdk-group-image-width`**\
  Specifies the width of the group image in pixels, controlling how large the group’s main image will appear.
* **`data-storysdk-group-image-height`**\
  Sets the height of the group image, allowing you to control the image’s vertical display size.
* **`data-storysdk-group-title-size`**\
  Adjusts the font size of the group title, so you can set the desired emphasis for the group title text.
* **`data-storysdk-group-class-name`**\
  Allows a custom CSS class to be applied to the individual group elements. Use this to apply unique styling to each group.
* **`data-storysdk-groups-class-name`**\
  Adds a custom CSS class to the container for multiple groups. This is useful for controlling overall styling for the collection of groups.
* **`data-storysdk-autoplay`**\
  Enables autoplay for stories if set to `"true"`. The stories will play automatically without requiring user interaction.
* **`data-storysdk-group-id`**\
  Identifies a specific group ID to load within the SDK, allowing targeted display of group content when autoplay is enabled.
* **`data-storysdk-start-story-id`**\
  Sets the initial story to display when the SDK opens, letting you direct users to a specific story.
* **`data-storysdk-forbid-close`**\
  Prevents users from closing the SDK interface if set to `"true"`. Useful for mandatory viewing scenarios.
* **`data-storysdk-is-show-mockup`**\
  Displays the story content within a device mockup if set to `"true"`, providing a preview within a simulated device frame.
* **`data-storysdk-is-status-bar-active`**\
  Activates a status bar at the top of the story if set to `"true"`, helping indicate story progress.
* **`data-storysdk-open-in-external-modal`**\
  Opens stories within an external modal if set to `"true"`. This is useful if you want to display content in a standalone modal overlay.
* **`data-storysdk-groups-outline-color`**\
  Specifies a custom outline color for groups. This is useful for visually highlighting or differentiating specific groups within the interface.
* **`data-storysdk-active-group-outline-color`**\
  Specifies a custom outline color for the active group or for the group when hovered over. This helps emphasize the currently selected or focused group in the interface.

Example of usage:

```html
<div
  id="storysdk"
  data-storysdk-token="YOUR_SDK_TOKEN"
  data-storysdk-group-image-width="150"
  data-storysdk-group-image-height="150"
  data-storysdk-group-title-size="18"
  data-storysdk-group-class-name="custom-group"
  data-storysdk-groups-class-name="custom-groups"
  data-storysdk-autoplay="true"
  data-storysdk-group-id="12345"
  data-storysdk-start-story-id="67890"
  data-storysdk-forbid-close="false"
  data-storysdk-is-show-mockup="true"
  data-storysdk-is-status-bar-active="true"
  data-storysdk-open-in-external-modal="false"
  data-storysdk-groups-outline-color="#e9e6e9"
  data-storysdk-active-group-outline-color="#fd19cc">
  <!-- Stories content goes here -->
</div>
```
