Skip to content

Destroy SDK

Call destroy() to clean up the SDK and reset all tracking data.


Usage

html
<script>
  // Clean up SDK when needed
  await AffiliateSDK.destroy();

  // SDK is now reset and can be re-initialized
  console.log("SDK destroyed");
</script>
php
<script>
  // On logout or page unload
  jQuery(document).ready(function() {
    jQuery('#logout-link').on('click', async function() {
      await AffiliateSDK.destroy();
    });
  });
</script>
liquid
<script>
  // Clean up on customer logout
  document.getElementById('logout-btn').addEventListener('click', async () => {
    await AffiliateSDK.destroy();
    window.location.href = '/account/logout';
  });
</script>
jsx
import { useEffect } from "react";
import { useRouter } from "next/router";

export default function Logout() {
  const router = useRouter();

  const handleLogout = async () => {
    // Destroy SDK before logout
    if (window.AffiliateSDK) {
      await window.AffiliateSDK.destroy();
    }

    // Then logout
    await fetch("/api/logout");
    router.push("/");
  };

  return <button onClick={handleLogout}>Logout</button>;
}
vue
<script setup lang="ts">
const router = useRouter();

const handleLogout = async () => {
  // Destroy SDK before logout
  if (window.AffiliateSDK) {
    await window.AffiliateSDK.destroy();
  }

  // Then logout
  await $fetch("/api/logout");
  await router.push("/");
};
</script>

<template>
  <button @click="handleLogout">Logout</button>
</template>

When to Use

  • User logout
  • Clearing session data
  • Re-initializing with different settings
  • Testing/debugging

Released under the MIT License.