Skip to main content
Version: Javascript tag

Examples

Common patterns for using the Screeb JS SDK in your application.

Basic setupโ€‹

Add the Screeb tag to your HTML <head>:

<script type="text/javascript">
(function (s,c,r,ee,b) {
s['ScreebObject']=r;s[r]=s[r]||function(){(s[r].q=s[r].q||[]).push(arguments)};
b=c.createElement('script');b.type='text/javascript';
b.id=r;b.src=ee;b.async=1;c.getElementsByTagName("head")[0].appendChild(b);
}(window,document,'$screeb','https://t.screeb.app/tag.js'));
$screeb('init', '<YOUR-WEBSITE-ID>');
</script>

Replace <YOUR-WEBSITE-ID> with your channel ID from workspace settings.


Identify a userโ€‹

Call identity() when a user logs in or when you have identity data available:

$screeb('identity', 'user-123', {
email: 'support@screeb.app',
firstname: 'John',
lastname: 'Doe',
plan: 'growth',
signed_up_at: new Date('2023-01-15'),
});

Or set identity during init():

$screeb('init', '<YOUR-WEBSITE-ID>', {
identity: {
id: 'user-123',
properties: {
email: 'support@screeb.app',
plan: 'growth',
}
}
});

Track an eventโ€‹

Send custom events to trigger surveys or enrich analytics:

$screeb('event.track', 'Clicked Upgrade Button', {
plan: 'free',
page: '/pricing',
});

Start a survey programmaticallyโ€‹

Trigger a survey by distribution ID:

$screeb('survey.start', 'distribution-uuid-here');

Or use the default distribution:

$screeb('survey.start', '');

Use hooksโ€‹

Register hooks to react to survey events:

$screeb('init', '<YOUR-WEBSITE-ID>', {
hooks: {
version: '1.0',
ready: function() {
console.log('Screeb SDK ready');
},
'survey.displayed': function(payload) {
console.log('Survey shown:', payload.survey.id);
},
'survey.completed': function(payload) {
console.log('Survey completed:', payload.survey.id);
},
}
});

Available hooks: ready, survey.displayed, survey.started, survey.completed, survey.closed, question.answered.


Alias an anonymous userโ€‹

When an anonymous user signs up, link their previous activity to their new identity:

// Before signup: anonymous user
$screeb('identity.properties', {
visited_pricing: true,
});

// After signup: alias to new identity
$screeb('identity.alias', 'user-123');

Reset on logoutโ€‹

Clear the current identity when a user logs out:

$screeb('identity.reset');

// Optionally set properties for the new anonymous session
$screeb('identity.properties', {
logged: false,
});