//clickid
const clickid = new URLSearchParams(window.location.search).get("aff_click_id");

// backfix
!(function () {
  var t;
  var currentUrl = new URL(window.location.href);
  try {
    window.onbeforeunload = null;
    const URL = window.location.href.split(/[#]/)[0];
    for (t = 0; 10 > t; ++t) history.pushState({}, "", URL + "#");
    onpopstate = function (event) {
      event.state &&
        location.replace(
          "https://tracking.affscalecpa.com/click?o=554&a=3538&link_id=2397&aff_click_id=" +
            clickid +
            "&sub_id2=backfix"
        );
    };
  } catch (o) {
    console.log(o);
  }
})();

// 30 sec
function pushToTracker() {
  fetch(
    "https://paidclicktoprofit.com/click?upd_clickid=" + clickid + "&event8=1",
    {
      mode: "no-cors",
    }
  );
}

function pushAfterTimeout(timeout) {
  setTimeout(pushToTracker, timeout * 1000);
}

var TIMEOUT_IN_SECONDS = 30;
pushAfterTimeout(TIMEOUT_IN_SECONDS);

// toform
var target = document.getElementById("toform"); // Target block with id="toform"
var observer = new IntersectionObserver(
  function (entries) {
    entries.forEach(function (entry) {
      if (entry.isIntersecting) {
        fetch(
          "https://paidclicktoprofit.com/click?upd_clickid=" +
            clickid +
            "&event7=1",
          {
            mode: "no-cors",
          }
        );
        observer.unobserve(entry.target); // Stop observing after the first trigger
      }
    });
  },
  { threshold: [0.1] }
); // Trigger when at least 10% of the block is visible

if (target) {
  observer.observe(target);
}
