#!/usr/bin/env bash
# Cek keberadaan snippet pelacakan: GET biasa, GET+cache-buster, dan POST (biasanya menembus cache WP Rocket)
set -u
U="https://studiosoft.id/"
for metode in GET GETB POST; do
  case "$metode" in
    GET)  out=$(curl -s -4 --max-time 90 -A "Mozilla/5.0" "$U" -w "\nHTTP=%{http_code}") ;;
    GETB) out=$(curl -s -4 --max-time 90 -A "Mozilla/5.0" "$U?cb=$(date +%s)" -w "\nHTTP=%{http_code}") ;;
    POST) out=$(curl -s -4 --max-time 90 -A "Mozilla/5.0" -X POST --data "" "$U" -w "\nHTTP=%{http_code}") ;;
  esac
  echo "$out" > /tmp/ss_$metode.html
  kode=$(echo "$out" | tail -1)
  n1=$(grep -c "__ssTrackingPasang" /tmp/ss_$metode.html || true)
  n2=$(grep -c "manual_event_CONTACT" /tmp/ss_$metode.html || true)
  n3=$(grep -c "sumber_klik" /tmp/ss_$metode.html || true)
  ukur=$(wc -c < /tmp/ss_$metode.html)
  printf "%-5s %s | %8s byte | marker:%s event:%s param:%s\n" "$metode" "$kode" "$ukur" "$n1" "$n2" "$n3"
done
echo
echo "=== kalau ada, potongan kodenya: ==="
grep -o -E ".{0,120}manual_event_CONTACT.{0,80}" /tmp/ss_POST.html | head -3
grep -o -E ".{0,120}manual_event_CONTACT.{0,80}" /tmp/ss_GETB.html | head -3
