Visitor attributes
Facts about the visitor your site knows: their plan, whether they're logged in, how many orders they've placed. Audiences can aim experiments at them (plan is pro), and recordings can be filtered by them.
// As early as you can: set before the snippet, it counts
// for this page's experiments too.
window.peekbird = window.peekbird || [];
peekbird.push(['set', {
plan: 'pro',
logged_in: true
}]);{% comment %} In layout/theme.liquid, before the snippet: {% endcomment %}
<script>
window.peekbird = window.peekbird || [];
peekbird.push(['set', {
logged_in: {% if customer %}true{% else %}false{% endif %},
{% if customer %}orders: {{ customer.orders_count }},{% endif %}
cart_items: {{ cart.item_count }}
}]);
</script>// In your theme's functions.php (or a code snippets plugin), before the snippet:
add_action('wp_head', function () {
$user = wp_get_current_user();
printf(
"<script>window.peekbird = window.peekbird || []; peekbird.push(['set', %s]);</script>",
wp_json_encode([
'logged_in' => is_user_logged_in(),
'role' => $user->roles[0] ?? 'visitor',
], JSON_HEX_TAG | JSON_HEX_AMP)
);
}, 1);<script>
window.peekbird = window.peekbird || [];
peekbird.push(['set', {
plan: {{DLV - user_plan}}
}]);
</script>The fields
names- Up to 20 per call, each up to 64 characters.
values- Text (up to 200 characters), numbers or true/false.
Good to know
- Set them as early as you can. Set before the snippet loads, they count for that page's experiments too.
- They're remembered for the visitor, so you don't need to set them on every page.
- To aim an experiment at them, add an audience condition "Your own attribute" with the same name.
- Recording filters need analytics on for the site (the default).