Including fpr.js

On your FirstPromoter dashboard, under the Settings> Integrations> Integrate your website section, based on the selections you make, you are provided with some scripts which are to be added to your website.

It is ideal that the script is added globally on the HEAD section of every marketing or public page of your website.

<script>(function(w){w.fpr=w.fpr||function(){w.fpr.q = w.fpr.q||[];w.fpr.q[arguments[0]=='set'?'unshift':'push'](arguments);};})(window);
fpr("init", {cid:"xxxxxxxx"}); 
fpr("click");
</script>
<script src="https://cdn.firstpromoter.com/fpr.js" async></script>

For JavaScript frameworks, you can simply insert the script on the public index.html page so it will be available when the framework loads.

For WordPress websites, you can add the scripts to your header.php file before the closing head tag.

To get the best performance, it is ideal that you have the scripts added to all the pages where you need tracking to take place. Also, the Scripts are loaded asynchronously and will not affect the website loading speed.

Functions

fpr(“init”,options, callback?)

This method helps initializes FirstPromoter with the provided options. Most of these options are loaded automatically when the script loads, but they can be overwritten by passing different ones to the method. The most used one is “ref_id” which forces the script to track a specific promoter.

Parameters

options
object
required

Available keys

PropertyDescription
cidFirstPromoter Company Id (required)
ref_idReferral id/token of the promoter
tidTracking ID, value stored in fprom_tid cookie
urlCurrent URL
domainCurrent domain
referrerBrowser referrer/ domain of the previous visited website

Setting properties that are not in the list above will be ignored.

callback
function

A function that will be called after the init function is triggered.

fpr(“click”,payload?, callback?)

This method is responsible for click tracking.

Parameters

payload
object

This overwrites the stored data exactly like the fpr(“init”…) function does before tracking the click.

Available keys

PropertyDescription
cidFirstPromoter Company Id
ref_idReferral id/token of the promoter
tidTracking ID, value stored in fprom_tid cookie
urlCurrent URL
domainCurrent domain
referrerBrowser referrer/ domain of the previous visited website

Setting properties that are not in the list above will be ignored.

callback
function

The callback function receives the response data object and can then be extracted and use

Example


fpr(“onReady”,callback)

This method checks if the tracking script is initialized and fully loaded on the page.

Parameters

callback
function

The callback function receives the response data object and can then be extracted and use

Example

click
fpr("onReady", function(data){
    console.log(data)
})

fpr(“referral”,payload, callback?)

This method is used primarily to send the referral details to FirstPromoter. It takes as its payload the email of the referral/lead

Parameters

payload
object
required

The callback function receives the response data object and can then be extracted and use

Available keys

PropertyDescription
emailactual email of the user
uiduser id of the user

Setting properties that are not in the list above will be ignored.

Example


fpr(“details”,callback)

This method is used in getting the details of the promotion and the promoter. To avoid making multiple requests, it is important to note that the details are stored in a cookie called “fprom_details” and is available for a day.

Parameters

callback
function

The callback function receives the response data object and can then be extracted and use

Response Format

{
      ref_id: 
      promo_code: 
      campaign_id: 
      customer_promo_code: 
      offer:  
      promoter: {
        id:  
        first_name:  
        last_name:  
      }
}

Example

click
fpr("details", function(data){
    console.log(data)
})

fpr(“crossDomain”,domains)

This method is used when attempting to track across multiple domains. It mainly appends the tracking details to all links to the domain provided. Note: this works with only direct links and should be added preferably to the footer section or called when the whole page is loaded

domains
string|array

The crossDomain(s) you want to track

Example

fpr(“urlTracking”)

This method is used for Direct URL tracking, thus, if you have landing pages for your affiliates/promoters, you can use the method on those pages if you don’t want the affiliates/promoters “Referral ID” to be part of their referral links.

For this method to work, you will have to first add FirstPromoter’s main tracking scripts to the landing page(s) and also enable “Direct URL tracking” on FirstPromoter. To do so, please check out this article: How to enable direct URL tracking in FirstPromoter

Please note that the method should not be used on your homepage, but instead should only be used on all landing pages of your affiliates/promoters.
<script type="text/javascript">
_fprom=window._fprom||[];window._fprom=_fprom;_fprom.push(["url_tracking",true]);
if (window.$FPROM){$FPROM.trackVisitor({url_tracking: true})} else if(window.fpr) fpr("urlTracking");
</script>