1.2.2 • Published 2 years ago

legiti v1.2.2

Weekly downloads
3
License
ISC
Repository
github
Last release
2 years ago

Legiti Antifraud

Legiti's antrifraud SDK for Javascript (browser) integrations.

Description

Legiti is a product developed to help your company to avoid fraudulent transactions. This README file should help you to integrate the Legiti Javascript library into your product with a couple steps.

How to use

The Legiti Javascript Library can be installed through npm or by a <script> (Global Variable) tag.

We recommend you to use the <script> tag (Global Variable) since this is a browser library.

Npm Method

First, install it:

npm install legiti

After that you can import the library as usual:

import legiti from 'legiti'

or using require

const legiti = require('legiti')

PS: If you are using Browserify check on how to make our variable global

Script Tag (Global Variable)

You can also use the latest release from our CDN and import the build directly in your HTML:

<script src="https://files.lgtcdn.net/legiti-js/v1/legiti.min.js" />

The library will be available as the global variable legiti.

API Docs

You can find more in-depth documentation about our frontend libraries and integrations in general here.

Library setup

In order to properly relay information to Legiti's processing pipeline, you'll need to provide your customer-specific authentication credential:

  • authToken (provided by Legiti)

P.S: Remember to use the sandbox authToken when you are not in production

With these, you can instantiate the Legiti tracking instance. Our integration library instantiates a singleton instance to prevent multiple trackers from being instantiated, which could otherwise result in duplicate or inconsistent data being relayed to Legiti.

The singleton instance is instantiated as follows:

  legiti.sharedInstance().setup(authToken="authToken", requestLocation=false);

Be advised, that this function can throw an exception if you pass invalids (empty strings or not in the format required) authToken.

All the access to the Legiti functions is made via calling the legiti.sharedInstance().

The parameters passed are the following, in order:

ParameterRequiredTypeDescription
authTokenYesStringAn unique identifier that the Legiti Team will provide to you
requestLocationYesBooleanIf set to true we will ask for the user's permission (which will help us provide more accurate results)

Library Calls

If you've already read the general Legiti files, you should be aware of all of Legiti requests and collection functions.

Here we will show you some details to be aware of if you are calling the Legiti tracking functions.

All of out track functions can throw exceptions, but the only exception they will throw is if you forget to configure the Legiti Library before calling one of them. Because of that the Legiti class have a function called isConfigured() that returns a boolean saying if you have configured or not the Legiti Library. We recommend that when you call any of our tracking functions you check if the Legiti Library is configured. Here is an example on how to do that:

if (legiti.sharedInstance().isConfigured()) {
    legiti.sharedInstance().trackUserCreation("123");
}

trackPageView

Pageview tracking is performed automatically by the library every time the user reloads the page or changes the url. We do provide the option to manually trigger "pseudo pageview" events (pageviews that do not change the page or do not change the url of the page). You should be careful when manually tracking pageviews since it can lead to duplicate pageview events. We recommend that you contact the Legiti team to get advice when using the trackPageView function.

Here you can see an example of manually triggering the trackPageView function:

if (legiti.sharedInstance().isConfigured()) {
    legiti.sharedInstance().trackPageView("Pseudo PageView")
}

Models

If you are coming from one of our backend libraries you will notice that we do not use models (e.g. Account, Sale) in our frontend libraries. Here you just need to send us the id of the model (e.g. sale ID, account ID).

More Information

For more info you should check the Legiti docs