@dub/analytics is a client-side script for tracking conversion events with Dub.

By default, the script handles the detection of the dub_id query parameter and storing it as a first-party cookie:

Then, when a conversion event occurs (e.g. a user signs up for an account), you can check for the dub_id cookie and attribute the conversion to the original click by tracking a lead event.

Finally, when the user completes a purchase (e.g. subscribing to a plan, purchasing a product, etc.), you can track a sale event. Under the hood, Dub will automatically attribute the sale to the original link click.