Javascript

Frizbit Javascript library enables you to integrate Frizbit's powerful user engagement solution into your website. This part of the document will help you to understand details of our javascript library. You can jump into our Web QuickStart Guide which will help you implement frizbit.js on your site in just a few minutes. Once you've completed the guide, you can return here to learn more about deeper integrations.

Getting Started

Frizbit Javascript library is designed to capture your website users' interaction in your website. It enables you to track your user's behaviors, identify them, and manage their permissions to send them marketing campaigns.

It consists of two different files:

  • Frizbit.min.js: Main javascript library which enables to track, identify and manage the permissions.
  • FrizbitServiceWorker.js: Service worker library in order to send web push notifications.

Both files are minified, gzipped and serving from our CDN.

Track

In order to send events to Frizbit, you can use the track method. Definition of the track method is below.

frizbit.track(eventname, metadata, options, callback);

The details of track method's parameters are below.

Parameter Type Description
eventname String The name of the action that you are tracking. You can use predefined or custom event name. Read Events section for best practices.
metadata optional Object A dictionary of extra information for the action. If the event was productViewed, it might have properties like price and categories.
options optional Object A dictionary of options.
callback optional Function A function that is executed after the method invocation.

Example of tracking when a user posting a review:

frizbit.track("reviewPosted", {
  review: "It is so easy to implement.",
  rating: 5.0
});

The only required parameter in track method is eventname. However, whenever possible, add event metadata to the track method, so that you can use more information about the event when you need to use it to analyze your customers behaviours.

Identify

After you integrate our javascript library, we will create an anonymous profile for each user who visits your website. However, if you have more information about the current user in your website, you can send details about the user using identify method as shown below.

frizbit.identify(userId, metadata, options, callback);

The details of identify method's parameters are below.

Parameter Type Description
userId optional String The identifier of the user in your database. If you don't know the user yet, you can omit the userId as its optional parameter.
metadata optional Object A dictionary of extra information about the user, like their name and email. You can set predefined metadata names for user profile or extend it by adding custom metadata that are specific to your business.
options optional Object A dictionary of options.
callback (optional) Function A function that will be executed after the method. invocation.

Ready

The ready method allows you to call something when initialization of Frizbit javascript library has completed. Code inside this function will only be executed after successful initialization of our library. The ready method definition is shown below.

frizbit.ready(callback);

The details of ready method's parameters are below.

Parameter Type Description
callback Function A function that will be executed after the successful initialization.

An example usage of ready method can be displaying a custom notify box to a user to ask her permission for sending web push notifications.

frizbit.ready(function() {
  showMyCustomNotifyBox();
});

User

If you need to get information about currently identified user, you can use user() method after the initialization of Frizbit javascript library has completed. In order to ensure user() method is available, wrap it in a ready() function block as shown below.

frizbit.ready(function() {
  var user = frizbit.user();
  var id = user.id();
  var metadata = user.metadata();
});

Load options

The .load method in installation snippet (the second line of the snippet) can also be modified to take a second argument. If you pass an object, then we will apply these settings internally to override the default options. The details of the options are shown below.

Parameter Type Description
serviceWorkerPath String The absolute location of the FrizbitServiceWorker.js file in the host.

Managing subscription process

The .subscribe method in installation snippet allows us to start subscription process automatically. If you want to manage subscription process manually, you can remove frizbit.subscibe(); line from the installation snippet and call this method whenever you want.

Troubleshooting

When you need to investigate whether something is broken or not, you can use browser's console to find out. In order to access the Javascript console in each browser:

  • Google Chrome: For Mac COMMAND+OPTION+J, for Windows CTRL+SHIFT+J.
  • Mozilla Firefox: For Mac COMMAND+OPTION+K, for Windows CTRL+SHIFT+K and then click Console tab.
  • Safari: COMMAND+OPTION+I and then click Console tab.

Check if Frizbit Javascript loaded successfully

Open the Javascript console in your desired browser and enter the website that you have implemented Frizbit javascript library. Enter frizbit. Does it return a result, as seen below?

Frizbit console successful

This means that you are successfuly loading Frizbit javascript library onto your website. If you are getting an error as shown below, this means Frizbit javascript is not loading successfully:

Frizbit console error

In this case, we recommend you to check our Web QuickStart Guide and re-follow the steps.

Check if you are able to send events

In order to invoke a track call manually, you can open the Javascript console and enter frizbit.track('test') as shown below:

Frizbit console track

After the invoking of the track method, check the Network tab to see if the requests for the tracking event are being initiated successfully:

Frizbit network track

If you don't see any network requests sent to frizbit.com, check if you are loading Frizbit javascript library successfully.


If you have any questions or see anywhere we can improve our documentation, please let us know!