Javascript Library - Storyberg/Docs GitHub Wiki

Identifying users

1. Install Storyberg Javascript tracking code

Paste this code just after the opening <head> tag on every page of your application.

<script type="text/javascript">
    var _sbq=_sbq||[];
    var _sbk=_sbk||"YOUR_API_KEY"; // TODO Add your Storyberg API Key
    function _sbs(e){setTimeout(function(){var t=document,n=t.getElementsByTagName("script")[0],r=t.createElement("script");r.type="text/javascript";r.async=true;r.src=("https:"==document.location.protocol?"https://":"http://")+e;n.parentNode.insertBefore(r,n)},1)}_sbs("https://s3.amazonaws.com/storyberg/js/analytics.js");
</script>

2. Identify logged in users

Add this code just after the opening <head> tag on every page where users are logged in (after the above code).

<script type="text/javascript">
  _sbq.push(['identify', {
    user_id: '1234', // TODO Output the current logged in users ID
    email: '[email protected]', // TODO Output the current logged in users email address
    sign_up_date: 1330779887, // TODO Output the current logged in sign up date as a Unix timestamp
    name: 'Test User' // TODO Output the current logged in users name
  }]);
</script>

3. Identify when a user 'sees' a new feature or experiment

a. Tag via Javascript

To record when a user sees a new feature or experiment, execute the following call.

<script type="text/javascript">
  _sbq.push(['identify', {
    user_id: '1234', // TODO Output the current logged in users ID (required)
    tag: 'EXPERIMENT TAG', // TODO Update with the experiment tag (optional)
  }]);
</script>

b. Tag via HTML

To automatically record when a user sees a new feature or experiment, add the following data attribute to any HTML element.

<div data-sb-tag="EXPERIMENT TAG">
    <!-- TODO Update data-sb-tag attribute with the experiment tag  -->
</div>

4. Record when a user does a key activity (event)

To record when a user does an activity, execute one the following calls.

a. Record key activity

<script type="text/javascript">
  _sbq.push(['event', {
    name: 'key',
  }]);
</script>

b. Record paid event

<script type="text/javascript">
  _sbq.push(['event', {
    name: 'paid', 
  }]);
</script>

c. Record custom event

<script type="text/javascript">
  _sbq.push(['event', {
    name: 'EVENT NAME', // TODO Update with an event name (no spaces)
  }]);
</script>
⚠️ **GitHub.com Fallback** ⚠️