Uniform plugin for Sanity
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 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#
In your Sanity project, install the Uniform Context plugin:
npm i @uniformdev/sanity-plugin-uniformOpen
sanity.config.ts
and add the following Uniform plugin definition. TheapiKey
andprojectId
can be retrieved from your Uniform project (use read-only API key here):import { uniformPlugin } from '@uniformdev/sanity-plugin-uniform' // add Uniform plugin to the plugins array: plugins: [uniformPlugin({ apiKey: '', projectId: '' })]In any schema you want to add personalization, add the following your fields array:
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 contentThis 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:
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:
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: