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.

  1. Landing script: This script is used to capture the token from the url params and store it using localStorage.
  2. Complete script: This script is used to automatically retrieve the token from localStorage and report the outcome via fetch().

Landing script

Requirements:

  1. 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.
  2. 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>

Complete script

Requirements:

  1. The page where you embedded the landing script must be different than the one where you embed the complete script.
  2. 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.

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.

Was this page helpful?