Skip to content

Insights Javascript Snippet

Our Javascript snippet can be found in the Insights->"Tracking Code" to find your account value. 

The snippet offers several functions:
  1. To "identify" a user on your web site, shopping cart, or application. This is done using the "identify" command. 
  2. To add or update a user in your Subscriber list. This is a function of the "identify" command. At a minimum the identified user's email is added. However, you are able to provide additional attributes which will then be added as well. These attributes correspond to the Subscriber fields that you have created (see the Subscribers->Fields section). If an email address exists, then any fields passed in using the "identify" command will be updated for that person.
  3. To track an identified user's behavior. Once an identify command is issued, the user is then tracked across any page that has loaded the snippet.
  4. To publish "events" to a person's profile. This is done using the "publish" command. 

Examples

Identify by email and publish a "visit" event


- user@example.com is identified and cookied
- a visit event is published to the user's profile
<script>
    window._ssstats = window._ssstats || [];
    _ssstats.push([
        'configure', {
            accountId: 12345
        }
    ]);
    _ssstats.push(['identify', 'user@email.com']);
    _ssstats.push(['publish', 'visit']);
</script>
<script src="//cdn.statstrk01.com/assets/javascripts/sdk2.js" async></script>

Identify and include first_name, last_name and publish a "visit" event


- add or update user@email.com and include first_name and last_name fields- a visit event is published to the user's profile
<script>
    window._ssstats = window._ssstats || [];
    _ssstats.push([
        'configure', {
            accountId: 12345
        }
    ]);
    _ssstats.push(['identify', 'user@email.com', {
      'first_name': 'John',
      'last_name': 'Doe'
    }]);
    _ssstats.push(['publish', 'visit']);
</script>
<script src="//cdn.statstrk01.com/assets/javascripts/sdk2.js" async></script>

Publish a "ordered" event to an already identified person


- an ordered event is published if the person is already profiled and has a tracking cookie
- the ordered event has an attribute called "monetaryValue" of 100, and an order_id of 123456
<script>
    window._ssstats = window._ssstats || [];
    _ssstats.push([
        'configure', {
            accountId: 12345
        }
    ]);
    _ssstats.push([
        'publish',
        'ordered', {
            monetaryValue: '100',
            order_id: '123456',
        }
    ]);
</script>
<script src="//cdn.statstrk01.com/assets/javascripts/sdk2.js" async></script>

Feedback and Knowledge Base