# Parameters

### Parameters list

#### Basic parameters

<table data-full-width="false"><thead><tr><th width="117">Id</th><th width="792">Description</th></tr></thead><tbody><tr><td><code>name</code></td><td><strong>String - Min. 3 chars</strong> - <em>Required</em><br>Readable name of the campaign.<br><em>E.g.</em><code>{"name":"My Engagement Campaign"}</code></td></tr><tr><td><code>live</code></td><td><strong>Boolean</strong> - <em>Required</em><br>Value that sets the campaign to live. A false value will save the campaign as a draft but not activate it<br><em>E.g.</em><code>{"live":true}</code></td></tr><tr><td><code>labels</code></td><td><strong>Array of Strings</strong> - <em>Optional - Max. 3 labels</em><br>An array containing the label names you want to attach to your campaign. You can use labels to filter the list of campaigns that appears on Batch's dashboard. Notice that related cappings are only applied to push Campaigns, but not on In-App Campaigns.<br><em>E.g.</em><code>{"labels":["label1","label2"]}</code></td></tr></tbody></table>

#### Timing and delivery

Two timezone parameters can be specified: `start_date` and `end_date`, and their counterparts `local_start_date` and `local_end_date`. If none of these parameters are specified, the In-App campaign will start now without any end date.

<table data-full-width="false"><thead><tr><th width="187.5">Id</th><th width="722.5">Description</th></tr></thead><tbody><tr><td><code>start_date</code></td><td><strong>String</strong> - <em>Optional - Conflicts with <code>local_start_date</code></em><br>Time that the In-App campaign will be activated GMT (UTC+0000). Format is <code>yyyy-MM-ddTHH:mm:ss</code> or <code>now</code> to activate the campaign immediately.<br><em>E.g.</em><code>{"local_start_date":"2015-12-01T14:25:00"}</code></td></tr><tr><td><code>local_start_date</code></td><td><strong>String</strong> - <em>Optional - Conflicts with <code>push_time</code></em><br>A value that defines the campaign activation time in terms of the user's device. The In-App campaign will be activated at the selected time for each time zone.<br>Format is <code>yyyy-MM-ddTHH:mm:ss</code><br><em>E.g.</em><code>{"local_start_date":"2015-12-01T14:25:00"}</code></td></tr><tr><td><code>end_date</code></td><td><strong>String</strong> - <em>Optional - Conflicts with <code>local_end_date</code></em><br>Time that the In-App campaign will end GMT (UTC+0000). Format is <code>yyyy-MM-ddTHH:mm:ss</code> .<br><em>E.g.</em><code>{"end_date":"2015-12-01T14:25:00"}</code></td></tr><tr><td><code>local_end_date</code></td><td><strong>String</strong> - <em>Optional - Conflicts with <code>end_date</code></em><br>A value that defines the campaign end time in terms of the user's device. The In-App campaign will end at the selected time for each time zone.<br>Format is <code>yyyy-MM-ddTHH:mm:ss</code><br><em>E.g.</em><code>{"local_end_date":"2015-12-01T14:25:00"}</code></td></tr></tbody></table>

#### Trigger

<table data-full-width="false"><thead><tr><th width="113.5">Id</th><th>Description</th></tr></thead><tbody><tr><td><code>trigger</code></td><td><strong>Object</strong> - <em>Required</em><br>An object describing when the In-App message will be triggered and displayed.<br></td></tr></tbody></table>

**Grace period**

The grace period avoids the In-App message to be displayed multiple times in a short time range.

<table data-full-width="false"><thead><tr><th width="163">Id</th><th>Description</th></tr></thead><tbody><tr><td><code>grace_period</code></td><td><strong>Object</strong> - <em>Optional</em><br>An object describing the grace period duration.<br><em>E.g.</em><code>{"grace_period":{"every":2,"unit":"DAYS"}}</code></td></tr></tbody></table>

**When**

<table data-full-width="false"><thead><tr><th width="87">Id</th><th width="787">Description</th></tr></thead><tbody><tr><td><code>when</code></td><td><strong>Object or String</strong> - <em>Optional</em><br>A string ( <code>NOW</code> or <code>NEXT_SESSION</code> ) or an object (if the trigger is an event) describing when the In-App message should be triggered.<br><em>E.g.</em><code>{"when":{"event":"e.event_name","label":"event_label"}}</code></td></tr></tbody></table>

#### User targeting

<table data-header-hidden data-full-width="false"><thead><tr><th width="126">Id</th><th width="788.5">Description</th></tr></thead><tbody><tr><td><code>targeting</code></td><td><strong>Object</strong> - <em>Optional</em><br>An object containing the targeting property of the campaign. If omitted, all users will be targeted.</td></tr></tbody></table>

#### Landing message

This will display a landing view using the theme and content of your choosing, allowing you to have complex interactions.

The landing message is defined under the `landing` key at the root of the payload and the following fields are allowed.

<table data-full-width="false"><thead><tr><th width="180">Id</th><th width="733.5">Description</th></tr></thead><tbody><tr><td><code>theme</code></td><td><strong>String</strong> - <em>Required</em><br>The code of the theme to use for your landing view<br><em>E.g.</em><code>{"theme":"dark_base_theme"}</code></td></tr><tr><td><code>tracking_id</code></td><td><strong>String</strong> - <em>Optional</em><br>A tracking ID that you will receive in your application if set<br><em>E.g.</em><code>{"tracking_id":"OPEA20161005"}</code></td></tr><tr><td><code>contents</code></td><td><strong>Array of Objects</strong> - <em>Required</em><br>The contents of the landing message. <a href="../../campaigns/advanced#language-and-country-codes">See here</a> for message localization rules and valid language codes.<br></td></tr></tbody></table>

> **Note**\
> If your theme contains the close button, the `actions` array is not strictly required.

**The action object**

Each action in the landing message must be defined as follows.

<table data-full-width="false"><thead><tr><th width="114.5">Id</th><th width="761">Description</th></tr></thead><tbody><tr><td><code>action</code></td><td><strong>String</strong> - <em>Required</em><br>The action name. Must match with the actions you register in your mobile application. Not strictly required, if null the close action will be used<br><em>E.g.</em><code>{"action":"show_article"}</code></td></tr><tr><td><code>label</code></td><td><strong>String</strong> - <em>Required</em><br>The label of the call to action<br><em>E.g.</em><code>{"label":"Show"}</code></td></tr><tr><td><code>args</code></td><td><strong>Object</strong> - <em>Optional</em><br>An object containing arbitrary data that will be passed to your action as is<br><em>E.g.</em><code>{"args":{"id":4,"category":"sports"}}</code></td></tr></tbody></table>

> **Important note**: You will find here a list of all the built-in actions you can use in your Mobile Landing to dismiss the In-App message, use a deeplink, and more : [iOS](https://doc.batch.com/developer/sdk/ios/advanced/custom-actions#built-in-actions) / [Android](https://doc.batch.com/developer/sdk/android/advanced/custom-actions#built-in-actions).

### The query object

For advanced usage, you can pass a query object to the targeting. This is a homemade syntax, inspired by MongoDB. This feature is available to **Pro** and **Enterprise** users for **native** and **custom** attributes.

#### Native attributes

Native attributes allow you to target users based on their OS and app version, their device type or the number of days since they installed your app.

Native attributes must be added in `query`, as a `targeting` property.

<table data-full-width="false"><thead><tr><th width="211.5">Id</th><th width="690.5">Description</th></tr></thead><tbody><tr><td><code>b.os_version</code></td><td><strong>String</strong> -<br>The Android or iOS version.The expected format is X.Y.Z. The OS version cannot contain any letter.<br><em>E.g.</em><code>{"b.os_version":"5.1.1"}</code></td></tr><tr><td><code>b.app_version</code></td><td><strong>String</strong> -<br>Your app version. The expected format is X.Y.Z.<br><em>E.g.</em><code>{"b.app_version":"2.A.3"}</code></td></tr><tr><td><code>b.device_type</code></td><td><strong>String</strong> -<br>The device type / model. Make sure you choose a value in the <code>model</code> column.<br><em>E.g.</em><code>{"b.device_type":"iPhone8,1"}</code></td></tr><tr><td><code>b.carrier_code</code></td><td><strong>Integer</strong> -<br>Your user's carrier. The code provided by Batch is a combination of the <em>Mobile country code (MCC)</em> and the <em>Mobile network code (MNC)</em> . The full list of MCC and MNC codes is <a href="https://en.wikipedia.org/wiki/Mobile_country_code">available here</a> . Not supported on iOS 16.4 and higher.<br><em>E.g.</em><code>{"b.carrier_code":20815}</code></td></tr><tr><td><code>age(b.install_date)</code></td><td><strong>Duration</strong> -<br>Number of days elapsed since the install <em>(install: the first time Batch SDK sees the user)</em> . The days are counted in sections of 24 hours from the hour of install.<br><em>E.g.</em><code>{"age(b.install_date)":1}</code></td></tr><tr><td><code>age(b.last_visit_date)</code></td><td><strong>Duration</strong> -<br>Number of days elapsed since your users' last session. The days are counted in sections of 24 hours from the last session.<br><em>E.g.</em><code>{"age(b.install_date)":1}</code></td></tr><tr><td><code>b.has_custom_id</code></td><td><strong>Boolean</strong> -<br>True if the user posesses a Custom User ID in our Userbase.<br><em>E.g.</em><code>{"b.has_custom_id":true}</code></td></tr><tr><td><code>b.transaction_tracked</code></td><td><strong>Boolean</strong> -<br>True if a transaction have been detected from the user.<br><em>E.g.</em><code>{"b.transaction_tracked":true}</code></td></tr><tr><td><code>b.city_code</code></td><td><strong>Integer</strong> -<br>You user's city detected by Batch using IP geolocation.<br><em>E.g.</em><code>{"b.city_code":2988507}</code></td></tr><tr><td><code>age(b.last_push_date)</code></td><td><strong>Duration</strong> -<br>Number of days elapsed since the last time you sent your user a push via the dashboard or the Campaigns API.<br><em>E.g.</em><code>{"age(b.last_push_date)":2}</code></td></tr><tr><td><code>isNear(int latitude, int longitude, string radius, duration time)</code></td><td><strong>Boolean</strong> -<br>True if the last collected user's location is within the given radius around the coordinates during the last X hours. Batch SDK must be allowed to collect geolocation to enable this query.<br><em>E.g.</em><code>{"isNear(48.8407578796295,2.351546582031233,5000m,12h)":true}</code></td></tr><tr><td><code>b.is_push_optin</code></td><td><strong>Boolean</strong> -<br>True if the install is opt-in to push, meaning that it can receive and display push notifications.<br><em>E.g.</em><code>{"b.is_push_optin":false}</code></td></tr></tbody></table>

By default, a `Duration` object is an Integer that represents a number of days. This object can be in any other time unit if it is given a String with the value and the unit. For instance `"12h"` represents a number of hours. *E.g.*`{"age(b.last_push_date)": “12h”}`

Instead of `age()`, you can also use `date()` on date attributes. This function will return a UTC timestamp Integer.

> **RECOMMENDED**<br>

* Users coming from an older version of your app and upgrading to a version with Batch's SDK *(after a first release or a token import)* are considered as new installs.<br>
* If you are planning to use this attribute to send 1-3-7 days post-install notifications, we recommend that you wait at least 7 days to make sure you only target your new users.

#### Custom user data

You can send custom user data from your app or using the [Custom Data API](https://doc.batch.com/developer/api/mep/custom-data-api/set-update).

**Attributes**

Custom attributes are prefixed with `c.` or `u.` if they are sent from the Custom Data API, and are simple key/value data. You can use them to collect a:

* String
* Number / Decimal
* Boolean
* Date

**Tags collections**

Tags are prefixed with `t.` or `ut.` if they are sent from the Custom Data API, and are sets of tags.

**Events**

Events are prefixed with `e.` and have a key, an occurence date, an optional label, and an optional data object.

> **Recommended**\
> Take a look at [this guide](https://github.com/BatchLabs/product.tech-documentation-gitbook/blob/master/guides/custom-data/README.md) to know more on custom data and learn how to tag your app.

#### Operators

* `$eq` Equal to. This is the default and thus can be ommited.
* `$lt` Lower than <
* `$lte` Lower or equal than <=
* `$gt` Greater than >
* `$gte` Greater or equal than >
* `$contains` Checks if the tag collection has one of the requested tag
* `$containsAll` Checks if the tag collection has all of the requested tag

**Basic examples**

Targets to all users who live in Paris :

```json
{
  "targeting": {
    "query": {
      "c.city": {
        "$eq": "Paris"
      }
    }
  }
}
```

As explained above, $eq is the default so we can ommit it:

```json
{
  "targeting": {
    "query": {
      "c.city": "Paris"
    }
  }
}
```

All users with app version 1.0.1

```json
{
  "targeting": {
    "query": {
      "b.app_version": {
        "$gte": "1.0.1"
      }
    }
  }
}
```

Users who installed your app 1 day ago and use an iPhone 6.

```json
{
  "targeting": {
    "query": {
      "$and": [
        {
          "age(b.install_date)": 1
        },
        {
          "b.device_type": {
            "$gt": "iPhone7,2"
          }
        }
      ]
    }
  }
}
```

When you need multiple conditions, the first level of your query needs to be an `$and`, with an array of conditions.

#### Functions and advanced example

Date attribute needs a function to be queried; that's why we showed you `age(b.install_date)` before.

We plan to introduce more functions to our API to enable events querying in the upcoming weeks.

From now on, we will only show the query. Just remember it goes in `targeting.query`.

*Users intersted by Rugby or Football, who installed in the last 10 days, and subscribed to your paid offer.*

```json
{
  "$and": [
    {
      "t.interest": {
        "$contains": ["Rugby", "Football"]
      }
    },
    {
      "age(b.install_date)": {
        "$lte": 10
      }
    },
    {
      "c.paidSubscriber": true
    }
  ]
}
```

*Users who installed your app since at least 10 days, living in Paris, at least Android 5.0, using the version 3.1.1 of your app, and subscribed to both France & Sport categories*

```json
{
  "$and": [
    {
      "age(b.install_date)": {
        "$gte": 10
      }
    },
    {
      "c.city": "Paris"
    },
    {
      "b.os_version": {
        "$gte": "5.0"
      }
    },
    {
      "b.app_version": "3.1.1"
    },
    {
      "t.push_optin": {
        "$containsAll": ["France", "Sport"]
      }
    }
  ]
}
```

> Please note that the **Imported** segment won't be selected if you target users based on custom user data (attributes, tags or events).

### cURL example

Here is an example of a valid cURL CLI request syntax:

```
curl -H "Content-Type: application/json" -H "X-Authorization: BATCH-PUSH-API-TOKEN" -X POST -d
"@payload.json" "https://api.batch.com/API_VERSION_NUMBER/BATCH_API_KEY/in-app-campaigns/create"
```

where `payload.json`:

```json
{
  "name": "Test Campaign",
  "local_start_date": "2017-06-01T14:00:00",
  "live": true,
  "targeting": {
    "languages": ["it"],
    "regions": ["FR", "US"],
    "segments": ["ONE_TIME", "ENGAGED", "NEW"],
    "query": {
      "age(b.install_date)": 1
    }
  },
  "trigger": {
    "capping": 3,
    "grace_period": {
      "every": 1,
      "unit": "DAYS"
    },
    "when": "NEXT_SESSION"
  },
  "landing": {
    "theme": "HELLO_THEME",
    "contents": [
      {
        "language": "en",
        "header": "Welcome",
        "title": "Hello!",
        "body": "How is it going?",
        "image": "https://static.batch.com/documentation/logo_batch_192.png",
        "actions": [
          {
            "label": "Continue",
            "action": "continue",
            "args": {
              "id": "1054"
            }
          }
        ]
      },
      {
        "language": "fr",
        "header": "Bienvenue",
        "title": "Salut!",
        "body": "Comment ça va ?",
        "image": "https://static.batch.com/documentation/logo_batch_192.png",
        "actions": [
          {
            "label": "Continuer",
            "action": "continue",
            "args": {
              "id": "1054"
            }
          }
        ]
      }
    ]
  }
}
```

The above example will start a recurring campaign on *June 1, 2015 at 14:00 (2PM)*, sending to users based on their device time.

* It is set as `"live": true` so will begin at the designated time, versus resting as a draft requiring further action before sending.
* The optional `targeting` object has been included to specify the device language, region, and targeted segments. If this object were not included, all users would be targeted. In this case, we used the native attribute `age(b.install_date)` to target users who installed the app one day ago.
* Within the `landing` object each targeted language has been given a message. It's worth noting that you must have a message object for the default language of your app, as set within the Batch dashboard.
* This campaign `trigger` here means that :
  * The message will be display 3 times to each user at the most
  * The message cannot be displayed more than one time in one day (24h)
  * The message will be displayed at the next session. It means that once the message is received by the device, it will be displayed the next time the user will open the app.
* This campaign uses the `recurrence` optional object to have the campaign repeat *every day* at the originally defined time of *14:00* until *June 6, 2015* at *00:00*.

### A/B Testing

A/B tested campaigns work a little bit differently than standard ones.

#### Landings

You can A/B test your landing message. To do that, you simply need to define two keys `a` and `b` under the `landing` key. Each key must contain a valid landing message object, as described above.

Here's a quick example of an A/B tested in-app campaign:

```json
{
  "landing": {
    "a": {
      "theme": "my-theme-1",
      "contents": [
        {
          "language": "fr",
          "title": "Salut!",
          "body": "Comment vas-tu?",
          "actions": [
            {
              "action": "batch.dismiss",
              "args": {},
              "label": "Annuler"
            },
            {
              "action": "batch.deeplink",
              "args": {
                "l": "https://google.fr/"
              },
              "label": "Rechercher"
            }
          ]
        },
        {
          "language": "en",
          "title": "Hey!",
          "body": "How are you?",
          "actions": [
            {
              "action": "batch.dismiss",
              "args": {},
              "label": "Cancel"
            },
            {
              "action": "batch.deeplink",
              "args": {
                "l": "https://google.com/"
              },
              "label": "Search"
            }
          ]
        }
      ]
    },
    "b": {
      "theme": "my-theme-2",
      "contents": [
        {
          "language": "fr",
          "title": "Bonjour!",
          "body": "Tu vas bien?",
          "image": "https://mydomain.com/myimage-1.png",
          "actions": [
            {
              "action": "batch.dismiss",
              "args": {},
              "label": "Annuler"
            },
            {
              "action": "batch.deeplink",
              "args": {
                "l": "https://google.fr/"
              },
              "label": "Rechercher"
            }
          ]
        },
        {
          "language": "en",
          "title": "Hi!",
          "body": "How is it going?",
          "image": "https://mydomain.com/myimage-2.png",
          "actions": [
            {
              "action": "batch.dismiss",
              "args": {},
              "label": "Cancel"
            },
            {
              "action": "batch.deeplink",
              "args": {
                "l": "https://google.com/"
              },
              "label": "Search"
            }
          ]
        }
      ]
    }
  }
}
```

> **Note**\
> Custom Payloads are not A/B testable.
