0.4.1 • Published 11 months ago

@bloomscorp/bloomsight.js v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

bloomsight.js

A client side javascript library to work with bloomsight.io

Badges

 License

Installation

Install using npm by running

npm install @bloomscorp/bloomsight.js

OR

Use our CDN url without installation. Make sure to change <VERSION> with appropriate release version of the library

https://cdn.jsdelivr.net/gh/bloomscorp/bloomsight.js@<VERSION>/umd/production.js
https://cdn.jsdelivr.net/gh/bloomscorp/bloomsight.js@<VERSION>/umd/dom.js 

Usage/Examples

Configuration

Use the init method to configure the library.

For ESModule projects

import {init} from '@bloomscorp/bloomsight.js';

init({
	propertyToken: '65d72f0b5e990c6028790156',
	isDevelopmentMode: true,
	...
});

For CommonJS projects

const {init} = require('@bloomscorp/bloomsight.js');

init({
	propertyToken: '65d72f0b5e990c6028790156',
	isDevelopmentMode: true,
	...
});

For CDN

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>


	<script src="https://cdn.jsdelivr.net/gh/bloomscorp/bloomsight.js@<VERSION>/umd/production.js"></script>
	<script>
		init({
			propertyToken: '65d72f0b5e990c6028790156',
			isDevelopmentMode: true,
			...
		});
	</script>
	<script src="./app.js"></script>
</body>

</html>

Below is the table with all the possible options that can be configured.

OptionTypeDescriptionMandatoryDefault
propertyTokenstringbloomsight.io property tokenNA
isDevelopmentModebooleanif true, then logs data in the browser consoleNA
stopSimpleEventbooleanstops only simple event trackingfalse
stopDataEventbooleanstops only data event trackingfalse
stopPageViewEventbooleanstops only page view event trackingfalse
stopAllbooleanstops all event trackingfalse
logOnlybooleantracks event but doesn't save to database. Should be used only when isDevelopmentMode: truefalse

Simple Event

Use the resolveSimpleEvent method to log simple events

import {resolveSimpleEvent} from '@bloomscorp/bloomsight.js';

resolveSimpleEvent(
	'65d735b122354c8ba6a489c2',
	'Contact Us CTA button'
);
OptionTypeDescriptionMandatoryDefault
eventTokenstringId of simple eventNA
labelstringa label/name for the event for future reference''

Data Event

Use the resolveDataEvent method to log data events

import {resolveDataEvent} from '@bloomscorp/bloomsight.js';

resolveDataEvent(
	'66d735b122355c8ba6a456f8',
	{
		productId: 120,
		sku: 'PROD021298'
	},
	'Add to Wishlist CTA button'
);
OptionTypeDescriptionMandatoryDefault
eventTokenstringId of data eventNA
eventDataObjectadditional metadata in key, value formatNA
labelstringa label/name for the event for future reference''

Page View Event

Use pageViewObserver to trigger page view events once your page is loaded. Ideally, the function should be triggered based on DOMContentLoaded or load event with a slight delay.

P.S: It is recommended to use appropriate library as per your framework from here which will handle page view events automatically.

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<script src="https://cdn.jsdelivr.net/gh/bloomscorp/bloomsight.js@<VERSION>/umd/production.js"></script>
	<script src="https://cdn.jsdelivr.net/gh/bloomscorp/bloomsight.js@<VERSION>/umd/dom.js"></script> // mandatory for DOM resolution
</head>
<body>


	
	<script>
		init({
			propertyToken: '65d72f0b5e990c6028790156',
			isDevelopmentMode: true,
			...
		});
	</script>
	<script>
		pageViewObserver();
	</script>
	<script src="./app.js"></script>
</body>

</html>

Send Email

Use sendEmail method to send email

import {sendEmail} from '@bloomscorp/bloomsight.js';

let formData = new FormData();
formData.append('name', 'John');
formData.append('email', 'john.doe@gmail.com');

sendEmail(
	'66d735b122355c8ba6a456f8',
	'63d735h822355s6ba6a4556k',
	'61d895h922355b6ba6a4587a',
	formData,
	() => alert('email sent successfully!'),
	() => alert('unable to send email! Try again later.')
)
OptionTypeDescriptionMandatoryDefault
engineIdstringId of the engine that will be used to send emailNA
templateIdstringId of the email template that will be used as email bodyNA
templateOwnerIdstringId of the user who has created the templateNA
emailMetaDataFormDataattachment & variables used in the template & their respective values in key, value formatNA
onSuccess() => voidcallback for operation success eventNA
onError() => voidcallback for operation error eventNA

Other Integration Options

If the framework impose limited control over the codebase but one have access to JS snippets, use the DOM based event resolution approach as below to use our library.

  1. Identify the DOM element where you want to integrate the event handler.
  2. Find a unique HTML element selector that can be used to select the DOM element. Note, the selector should follow standards as mentioned here.
  3. Use the resolveDOM function to pass on the selector and the event handler.
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<script src="https://cdn.jsdelivr.net/gh/bloomscorp/bloomsight.js@<VERSION>/umd/production.js"></script>
	<script src="https://cdn.jsdelivr.net/gh/bloomscorp/bloomsight.js@<VERSION>/umd/dom.js"></script>
</head>
<body>


	
	<script>
		init({
			propertyToken: '65d72f0b5e990c6028790156',
			isDevelopmentMode: true,
			...
		});
	</script>
	<script>
		resolveDOM("button[type=submit]", () => resolveSimpleEvent('61d895h922355b6ba6a4587a'));
	</script>
	<script src="./app.js"></script>
</body>

</html>

Note: Make sure the element selector is unique within the page. If there are multiple elements present in the page with same selector, then only the first element will be considered for event resolution.

License

MIT

Support

Report issues or feature requests here

0.4.1

11 months ago

0.4.0

1 year ago

0.3.15

1 year ago

0.3.14

1 year ago

0.3.13

1 year ago

0.3.12

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.6

1 year ago

0.3.7

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.2

1 year ago

0.3.3

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago