Getting Started

The JavaScript Web API allows you to interact with Prefinery using JavaScript. You can add new users, trigger referrals & rewards, and display embeddable widgets.

Step 1: Install the Prefinery JavaScript Snippet

The first step is to install the Prefinery JavaScript Snippet on your website, which can be done by following these steps:

1. Go to your project and click on the Installation link and copy your project's unique JavaScript Snippet.

2. Add the JavaScript Snippet into the <head> section of your website so that it loads on each webpage.

When you install the Snippet, your pages get access to the global window.prefinery object, which you will use to make calls to the API.

Note: The Prefinery JavaScript Snippet has changed slightly. If you copied & pasted the snippet into your website before January 17, 2021 you should perform the installation instructions again, copying the up-to-date snippet and re-installing on your website.

Next, check out the tutorials.

Content Security Policy (CSP) Requirements

If your website uses a Content Security Policy, you must allow Prefinery assets and endpoints or the JavaScript snippet and embedded widgets may fail to load.

Start with these directives and adjust based on your integration:

script-src 'self' https://i.prefinery.com https://www.prefinery.com;
connect-src 'self' https://i.prefinery.com https://www.prefinery.com;
frame-src 'self' https://i.prefinery.com https://www.prefinery.com;

If your policy uses child-src instead of frame-src, include Prefinery hosts there. Some integrations may require additional domains for your own analytics tools and custom scripts.

Tip: Roll out CSP changes in report-only mode first to collect violations before enforcement.