Using Endlinks with embeddable scripts
We also offer another option for very simple use cases that only need to report success. TARTLE provides
two javascript files you can embed on your html via <script>
tags. If you use these scripts, you won't need
to manually handle the token or report the outcome, but there are some important limitations to be aware of.
This solution is not recommended for Single Page Applications (SPA). You would need to add code to dynamically add and remove scripts, which can be tricky and error prone. For SPA's we recommend using the client-side solutions in the api calls or browser redirects sections.
- Landing script: This script is used to capture the token from the url params and store it using
localStorage
. - Complete script: This script is used to automatically retrieve the token from
localStorage
and report the outcome viafetch()
.
Landing script
Requirements:
- The script must be added to the page that corresponds to the endlink url you added on the packet, since it needs to read the query params to be able to save the token.
- There must be no redirects in this flow, if the user is redirected to log in automatically for example, the script will not have enough time to save the token.
Embedding the landing script
<script src="https://source.tartle.co/scripts/endlink-landing.js"></script>
For an example of a page that would work as an endlink destination, see this example landing page
Complete script
Requirements:
- The page where you embedded the landing script must be different than the one where you embed the complete script.
- There must be no redirects in this flow, if the user is redirected to log in automatically for example, the script will not have enough time to save the token.
Embedding the complete script
<script src="https://source.tartle.co/scripts/endlink-completion.js"></script>
This script will make the api call as soon as the script is loaded and executed, so it's best to make a completion page to inform the user they are done and they were successful, and embedding the script on that page.
Here is an example of a completion page
Best use cases
When using these scripts you can only report sucesss (completion). Any user packets that go to your endlink url and don't end up in a completion page will remain incomplete. This is why it's important that you make sure you follow the requirements in both sections above to avoid false negatives where the user completes your requirements but completion is not reported, which will result in loss of possible profits for the user.
The best use case for this is for sites that are rendered as separate html pages, and flows that do not rely on redirects upon landing.
Even in the best of circumnstances, since this is a client-based flow you can end up with false positives because of old browsers, security settings that prevent access to localStorage, and other issues. For better reliability, we recommend using the server examples for api calls or browser redirects.