Website data (ply.setData and plyData)
Website data is a set of key/value pairs your site passes to Personizely for the current browser session, such as a loyalty tier, a page type, a cart value from a custom cart, or a flag from your backend. You set it with ply.setData, the window.plyData object or a parser, target it with the Data filter, and print it in widgets and campaigns with {data.key} dynamic text. Unlike visitor fields, website data isn't saved to the visitor's profile.
Available on: all platforms.
How it works
- Your site sets values before or after the snippet loads.
- Personizely keeps them for the browser session. They're shared across tabs and pages of the same site and cleared when the session ends (when every tab of your site is closed).
- Targets read them with the Data filter when they're evaluated: on page load, on page changes and when a widget trigger fires.
- Dynamic text updates live. Every {data.key} on the page re-renders as soon as you set a new value for that key.
Setting data
window.plyData (before the snippet loads)
Define a global object in your page, above the Personizely snippet:
<script>
window.plyData = { pageType: 'product', loyaltyTier: 'gold', pointsBalance: 1250 };
</script>It's read once, when the snippet starts on each page load, and merged with the data already stored for the session. Changing window.plyData later has no effect; use ply.setData.
ply.setData (any time)
ply.setData('loyaltyTier', 'gold');
ply.setData({ loyaltyTier: 'gold', pointsBalance: 1250 });If your code might run before the snippet has loaded, queue the call:
window.plyLayer = window.plyLayer || [];
window.plyLayer.push(['setData', 'loyaltyTier', 'gold']);See the JavaScript API for details.
Parsers (no code)
A parser with destination Data copies a JavaScript variable, cookie, local storage key, URL parameter or element text into a data key on every page load. See Parsers.
Using data
With the Data filter
Add the Data filter to a target. It reads "Data matches all the following conditions"; each condition is Key, an operator and a value, and every condition must be true.
Operator | True when the stored value |
|---|---|
is / is not | Equals / doesn't equal the value, compared as text and case-sensitive. true matches the boolean true and the text "true" |
contains / does not contain | Contains / doesn't contain the value as text |
is empty / is not empty | Is missing, an empty string, false or the number 0 / is anything else |
is higher than / is lower than | Is a number above / below the value. The first number in the text is used, so "$1,299.99" reads as 1299.99 |
is checked / is not checked | Is set to anything other than an empty string, false or the number 0 / is one of those or missing. The text "false" counts as checked, so pass real booleans |
With dynamic text
Write {data.key} in a widget's text, a link, or a campaign change. Add a fallback for visitors without the value: {data.loyaltyTier or 'member'}. See Dynamic text.
Behavior details and limitations
- Top-level keys only. ply.setData('customer', { tier: 'gold' }) stores an object under customer; the Data filter and {data.*} can't read customer.tier. Set customerTier instead.
- Keys for dynamic text must be letters, digits and underscores, such as loyalty_tier or loyaltyTier.
- Session scope. Data lasts for the browser session and is kept separately for each subdomain. It isn't attached to the visitor's profile; use ply.identifyVisitor or a parser with destination Visitor for that.
- Values persist until overwritten. Setting pageType on one page doesn't clear it on the next. Set page-specific keys on every page, or set them to an empty string where they don't apply.
- Campaigns aren't re-run when data changes. A campaign that didn't match on page load stays off until the next page load or page change. Widgets re-check their Target rule when their trigger fires, so data you set before then counts. See How targeting works.
- Set data early for campaigns. For a campaign to see a value on the current page, set it with window.plyData or plyLayer before the snippet starts.
Examples
- Logged-in tier on a custom platform: your template renders window.plyData = { loyaltyTier: '{{ customer.tier }}' }. A personalization targets "Data: loyaltyTier is gold" with a members-only banner.
- Quiz result for the session: your quiz calls ply.setData('quizResult', 'oily') on completion. A widget with a Target of "Data: quizResult is oily" and a Click trigger shows matching products; the headline says "Picked for {data.quizResult} skin".
- Backend experiment flag: your server decides a shipping offer and renders window.plyData = { freeShippingEligible: true }. A target with "Data: freeShippingEligible is checked" shows the free-shipping bar.
Troubleshooting
- Data filter never matches → the key's capitalization differs, the value is nested in an object, or window.plyData was set after the snippet started.
- Campaign doesn't apply, widget does → the value was set after page load. Set it before the snippet runs, or reload.
- {data.key} shows the fallback → the key isn't set in this session, or its value is empty, 0 or false.