This guide will show you how to setup Frizbit's Javascript library on your website, track events and identify users.
Step 1: Add the Snippet
Copy and paste the code snippet below inside the <head></head> section of your website.
<script type="text/javascript">
!function(){var frizbit=window.frizbit=window.frizbit||[];if(!frizbit.initialize){if(frizbit.invoked){window.console&&console.error&&console.error("Frizbit snippet included twice.")}else{frizbit.invoked=!0;frizbit.methods=["identify", "user", "track","ready","debug","pageViewed","once","off","on","subscribe"];frizbit.factory=function(t){return function(){var r=Array.prototype.slice.call(arguments);r.unshift(t);frizbit.push(r);return frizbit}};for(var t=0;t<frizbit.methods.length;t+=1){var r=frizbit.methods[t];frizbit[r]=frizbit.factory(r)}frizbit.load=function(t,r){r=r||{};var i="https://cdn.frizbit.com/js/",n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=i+"frizbit.min.js";var o=document.createElement("link");o.rel="stylesheet",o.href=i+"frizbit.min.css";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);a.parentNode.insertBefore(o,a);frizbit._loadOptions=r;frizbit._loadOptions.appKey=t};
frizbit.SNIPPET_VERSION="0.0.4";
frizbit.load("YOUR_APP_KEY");
frizbit.pageViewed();
frizbit.subscribe();
}}}();
</script>
Please replace YOUR_APP_KEY with your Frizbit website's App Key, which you can find in your website quick install section or settings.
This snippet will load frizbit.min.js and frizbit.min.css files onto the page asynchronously, so it won't affect your page load speed.
Step 2: Upload FrizbitServiceWorker.js
In order to allow your users to subscribe notifications in your website, you'll need to add FrizbitServiceWorker.js file to your website.
- Download latest FrizbitServiceWorker.js here.
- Upload it to the top-level root of your site directory, so that make them publicly accessible as
https://yoursite.com/FrizbitServiceWorker.js
If you are having problem with uploading FrizbitServiceWorker.js on your server, check our troubleshooting section or contact us.
Step 3: Identify Users
Frizbit's Javascript library helps you to create a user profile for every person visiting your website. Initially, Frizbit will automatically assign an anonymousId to each visitors of your website, so that every visitors' actions can be still tracked.
To enrich the user profile with information, such as the user's name or email, you can call identify method of Frizbit javascript library. Here's an example showing how to identify a user with an unique ID and add a name and an email to a user's profile by using identify call:
frizbit.identify("1f5273aa2b18", {
name: "Mary Poppins",
email: "mary@waltdisney.com"
});
Let's examine the code block above. The code block fires an frizbit.identify() call with two parameters:
- User ID:
1f5273aa2b18. This is an unique identifier that represents the visitor in your database. - Metadata:
{name: 'Mary Poppins', email: 'mary@waltdisney.com'}. This is an optional parameter that you can pass toidentifycall in order to send more information about the visitor. We recommend you to check our predefined metadata reference.
When you actually make the identify call on your site, you'll need to replace all those hard-coded strings with details about the currently logged-in user. To achive that, we recommend using a backend template to inject an identify call straight into the footer of every page of your site where the user is logged in. Depending on your templating language, that would look something like this:
frizbit.identify("{{ current_user.id }}", {
name: "{{ current_user.fullname }}",
email: "{{ current_user.email }}"
});
With this call on your page, no matter what page the user first lands on, they will always be identified.
Step 4: Track Events
When your visitors explores your website, Frizbit captures which actions they are performing on your website. Frizbit javascript library track method enables you to track actions that are specific to your needs. Here is a simple example how to track when a product detail was viewed:
frizbit.track("productViewed");
That code above is enough to track an event. However, it is not telling much about which product was viewed. To enrich the information about the product that was viewed, you can send metadata as a second parameter to track call as shown below.
frizbit.track("productViewed", {
product: {
id: "#12F5B9",
name: "Xbox PS",
price: "154",
category: "Console",
categories: ["Entertainment", "Game", "Console"]
}
});
While implementing event tracking, we recommend you to check our predefined event list so that you'll have more structured events in your website.
Start by tracking just a few important events such as productViewed, productAddedToCart, productsPurchased and add more later.
Troubleshooting
How do I upload a file to my website?
There are three ways you can upload a file to your website:
FTP: If you have an access to your host, use an FTP server like FileZilla to upload a file to your root directory.
Control Panel: Some hosting providers are providing control panel like cPanel. Access your control panel and use it to upload a file.
Contact your hosting provider: If you don't have any access to either FTP or Control Panel, you can ask your hosting provider to upload a file to your website's root directory.
If you have any questions or see anywhere we can improve our documentation, please let us know!