# Uniform plugin for Sanity

> Add personalization to Sanity CMS

Source: https://docs.uniform.app/docs/integrations/content/sanity/sanity-plugin

This plugin augments Sanity Studio with ability to assign personalization criteria and enrichments tags to any documents inside your Sanity dataset.

> **Before you start:**
>
> If you are already using [Sanity integration](https://docs.uniform.app/docs/integrations/content/sanity/sanity-integration) within Uniform and building components and compositions inside Uniform, then you may not need this integration. Consult your Uniform Solution Architect before proceeding.

## Install Sanity plugin

1. In your Sanity project, install the Uniform Context plugin:

   ```shell
   npm i @uniformdev/sanity-plugin-uniform
   ```
2. Open `sanity.config.ts` and add the following Uniform plugin definition. The `apiKey` and `projectId` can be retrieved from your Uniform project (use read-only API key here):

   ```typescript
   import { uniformPlugin } from '@uniformdev/sanity-plugin-uniform'

   // add Uniform plugin to the plugins array:
   plugins: [uniformPlugin({
      apiKey: '',
      projectId: ''
   })]

   ```
3. In any schema you want to add personalization, add the following your fields array:

   ```typescript
   defineField({
      name: 'personalizationCriteria',
      title: 'Personalization Criteria',
      type: 'uniform.personalizationCriteria',
   })
   ```

   Adding this field augments your type with a new field allowing to assign personalization criteria to your Sanity content:

   ![Add personalization criteria to your Sanity content](https://docs.uniform.app/images/integrations/content/sanity/sanity-p13n-crit.png)
4. This is optional and is needed only if you use enrichments. In any schema you want to add enrichments, add the following to the fields array:

   ```typescript
   defineField({
      name: 'enrichmentTags',
      title: 'Enrichment Tags',
      type: 'uniform.enrichmenttags',
   })
   ```

Adding this field augments your type with a new field allowing to assign enrichment tags to your Sanity content, which is instrumental to feed Uniform tracker with behavioral information while visitors are browsing your site, which allows to use enrichment scores for behavioral personalization:

![Tag your content with Uniform enrichments](https://docs.uniform.app/images/integrations/content/sanity/sanity-enrichment-tags.png)

## Add Uniform SDK into your app

Now you are able to store personalization criteria and enrichment tags along side your Sanity content.
The last step is to perform a on-time addition of Uniform SDK into your front-end.

The easiest way to start is to check out one of the following open sourced examples:

- [Sanity demo](https://github.com/uniformdev/uniformconf-context-sanity)
- [Vanilla starter for Next.js](https://github.com/uniformdev/examples/tree/main/examples/context-edge-vercel)
