Documentation menuEcommerce: ThriveCart

Ecommerce

Add Loogika to ThriveCart

The Loogika tag goes into the custom scripts that ThriveCart accepts for each checkout page. The success page of the checkout is the place to send a purchase event. Because ThriveCart strips data attributes off script tags, the script address has to hold the site ID.

Last updated .

What do you need before you start?

Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own 12-character site ID in place of YOUR_SITE_ID:

<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>

The Loogika tag carries the site ID in its address, so it keeps working after ThriveCart has removed the data attributes.

How do you add the Loogika tag to a ThriveCart checkout?

Paste the tag into the header scripts field of the checkout page. ThriveCart stores scripts per checkout, so each checkout that should be tracked needs the same steps.

  1. Open the relevant checkout page from your ThriveCart dashboard.
  2. Go to Settings, then Tracking, and find the custom scripts section.
  3. Paste the tag into the header scripts field and save.

Can the checkout and your main site share one site ID?

Yes. Your checkout may run on a subdomain, for example sales.yourdomain.com, and still use the site ID of your main site. Loogika then reports both under one site, and a funnel can follow a visitor from your site to the purchase.

How do you track purchases in ThriveCart?

Add the script below to the success page of the checkout, then set the values in its first lines. ThriveCart also gets in the way of inline events when they fire. The script for that reason loads the Loogika script itself when it is missing and waits until it is ready.

<script>
(function () {
  var EVENT_NAME = "purchase";
  var PAYLOAD = { content_name: "Your Product Name", value: 97.0, currency: "USD" };
  var SITE_ID = "YOUR_SITE_ID";
  var SCRIPT_SRC = "https://app.loogika.com/api/script.js?siteId=" + SITE_ID;

  // Send once per session, even on refresh or back navigation
  var SENT_KEY = "loogika_" + EVENT_NAME + "_sent_v1";
  try {
    if (sessionStorage.getItem(SENT_KEY) === "1") return;
    sessionStorage.setItem(SENT_KEY, "1");
  } catch (e) {}

  function isReady() {
    return window.loogika && typeof window.loogika.event === "function";
  }
  function send() {
    window.loogika.event(EVENT_NAME, PAYLOAD);
  }
  function waitThenSend(timeoutMs) {
    var start = Date.now();
    (function check() {
      if (isReady()) return send();
      if (Date.now() - start < timeoutMs) setTimeout(check, 150);
    })();
  }

  if (isReady()) return send();
  if (!document.querySelector('script[src="' + SCRIPT_SRC + '"]')) {
    var s = document.createElement("script");
    s.src = SCRIPT_SRC;
    s.defer = true;
    document.head.appendChild(s);
  }
  waitThenSend(8000);
})();
</script>

The script writes a marker to sessionStorage, the storage a browser keeps for one tab session. A visitor who refreshes the success page or goes back to it sends the event only once.

ValueWhat you fill in
EVENT_NAMEThe name of the event, for example purchase or checkout_complete
PAYLOADThe product name in content_name, the amount in value and the currency code in currency, such as USD, GBP or EUR
SITE_IDYour Loogika site ID

Each page has one fixed payload. A shop with several products therefore needs one success page for each product. You can also fill PAYLOAD from the dynamic variables of ThriveCart where they are available.

How do you check that Loogika is installed?

Open the live checkout page in a new tab. The pageview shows up in the Loogika dashboard within a few seconds. If nothing arrives, look for script.js?siteId= in the page source.

Why does ThriveCart not send data to Loogika?

SymptomCause and fix
Script tag attributes have no effectThriveCart removes data attributes, which disables options like data-skip-patterns on its pages. Keep the site ID in the address
A purchase is counted twiceCheck that the event script sits on the success page only once. Clear the session storage of your browser before you test again
The script never loadsTry the footer scripts field in place of the header field. You can also ask ThriveCart support to confirm that custom scripts are enabled on your account