1.0.2 • Published 2 years ago

@spare.io-organization/sdk v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@spare.io-organization/sdk

Usage

CDN

Put the script into the head section of your website:

<script src="https://unpkg.com/@spare.io-organization/sdk@1.0.2/umd/sdk.min.js"></script>

The script must be included to all of the pages you specify when creating/editing products on the spare.io platform to be able to track the number of visitors coming from a particular Ad.

To track purchases, call the following script when a purchase occurs:

__spare.purchase({price: 99.99});

The price value (eg. 99.99) is used to properly calculate revenue and other metrics displayed on the Ad Manager page.

You can find an example below that shows how it can look in HTML code of your page:

<h1>Product title</h3>
<button onclick="__spare.purchase({price:99, orderId: 123})">Buy</button>

If you are using HTML forms for purchases you need to register purchaseWithForm in a head section of your app and specify id of the target form as shown below:

<head>
  ...
  <script src="https://unpkg.com/@spare.io-organization/sdk@1.0.2/umd/sdk.min.js"></script>
  <script>
    __spare.purchaseWithForm("buy-form", {price: 1100, orderId: 123});
  </script>
</head>
<body>
  <form id="buy-form" action="/buy" method="post">
    ...
    <button type="submit">Buy</button>
  </form>
</body>

ESM

There is also an option to use the package in ES modules format.

The __spare instance will not be accessible globally from a window object when using ES modules

Install package with npm or yarn

npm install @spare.io-organization/sdk
import {init} from "@spare.io-organization/sdk";

// Track info about purchase
spare.purchase({
  price: 99.99,
  orderId: 123
});

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Live updates with wml

You might need to debug your code if you are going to contribute to this package.

There is a WML tool that will allow you to to perform live mapping of library into the node_modules of the dependent project.

# You need to add a link only once
wml add ./ ~/dependent-project/node_modules/@spare.io-organization/sdk

wml start

License

MIT License

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago