@upst/iframe-funding-form
v2.0.0
Published
Upstart's `@upst/iframe-funding-form` SDK enables partners to embed Upstart's funding form on to their own sites via an iFrame. Partners will simply call this clientside SDK to open offer URLs.
Downloads
1,408
Readme
@upst/iframe-funding-form
Upstart's @upst/iframe-funding-form
SDK enables partners to embed Upstart's funding form on to their own sites via an iFrame. Partners will simply call this clientside SDK to open offer URLs.
Setup
Choosing the Right Installation Method
npm (node package manager)
This method is recommended for modern web applications. The Upstart Embedded Browser SDK is packaged with the rest of your front-end JavaScript code. It has no impact on page load performance and can be dynamically imported when needed.
CDN async
This method is recommended for web applications with performance targets. The Upstart Embedded Browser SDK loads from a CDN asynchronously, ensuring the SDK download does not impact page load performance. However, the SDK may be slow to initialize if it's called early in the page's load.
CDN sync
This method is recommended if the Upstart Embedded Browser SDK needs to be initialized immediately. The SDK loads from a CDN synchronously, ensuring the SDK loads earlier in a page's lifecycle. This method may impact page load performance.
npm
Add @upst/iframe-funding-form
to your package.json
file, then initialize it with:
import UPST from '@upst/iframe-funding-form'
...
UPST.init({ offerUrl: '<upstart.com offer url>' })
...
<script>
(function(l,o,a,n,s) {
l=l[s]=l[s]||{q:[],onReady:function(c){l.q.push(c)}}
s=o.createElement(a);s.async=1;s.src=n
n=o.getElementsByTagName(a)[0];n.parentNode.insertBefore(s,n)
})(window,document,'script','https://www.unpkg.com/@upst/iframe-funding-form@<PACKAGE_VERSION>/dist/umd/bindle.min.js','UPST')
window.UPST.onReady(function() {
...
window.UPST.init({ offerUrl: '<upstart.com offer url>' });
...
})
</script>
CDN Sync
<script
src="https://www.unpkg.com/@upst/iframe-funding-form@<PACKAGE_VERSION>/dist/umd/bundle.min.js"
type="text/javascript"
></script>
<script>
...
window.UPST && window.UPST.init({ offerUrl: '<upstart.com offer url>' })
...
</script>
Usage
Above we have listed methods on how best to donwload and use our Javascript SDK. In terms of usage, it is important to note that upst.init({CONFIG})
should be called when the code is expected to open the iFrame. The most common use case is a button/link on your site that is expected to open the offer url. Instead of directly linking to the offer url, simply add a button event handler on the button, then when the button is clicked upst.init
is called with the offer url.
import * as React from "react";
import UPST from "@upst/iframe-funding-form";
const UpstartIframeButton = (): React.ReactElement => {
return (
<Button
onClick={(e) => {
e.preventDefault();
UPST.init({ offerUrl: iframeUrl });
}}
>
Open Upstart iFrame
</Button>
);
};
export default UpstartIframeButton;
Alternatively, you might want to open the iFrame in other use cases, such as on page load. If that is the case, simply calling upst.init
when your conditions are met with a valid offer URL will trigger the iframe to open.