<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//trendykool.com/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://trendykool.com/post-sitemap.xml</loc>
		<lastmod>2026-03-31T14:25:14+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://trendykool.com/page-sitemap.xml</loc>
		<lastmod>2025-10-13T10:32:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://trendykool.com/product-sitemap.xml</loc>
		<lastmod>2025-11-17T09:23:29+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://trendykool.com/category-sitemap.xml</loc>
		<lastmod>2026-03-31T14:25:14+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://trendykool.com/product_cat-sitemap.xml</loc>
		<lastmod>2025-11-17T09:23:29+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://trendykool.com/author-sitemap.xml</loc>
		<lastmod>2025-12-17T20:13:07+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->
<!-- Affiliate Network Tracking Script (Inline): AN_6923591b_ljfhisdztdxrwlhipyqwh -->
<script type="text/javascript">
(function() {
  'use strict';
  
  // Configuration
  var API_URL = 'https://affiliateshares.onrender.com';
  var TRACKING_CODE = 'AN_6923591b_ljfhisdztdxrwlhipyqwh';
  var COOKIE_NAME = 'affiliate_ref';
  var COOKIE_DURATION = 60; // days
  var TRACKING_COOKIE = 'affiliate_tracking';
  
  // Utility functions
  function getCookie(name) {
    var value = "; " + document.cookie;
    var parts = value.split("; " + name + "=");
    if (parts.length === 2) return parts.pop().split(";").shift();
    return null;
  }
  
  function setCookie(name, value, days) {
    console.log('[Affiliate Network] Attempting to set cookie:', name, '=', value, 'for', days, 'days');
    
    var expires = new Date();
    expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
    
    // Try multiple cookie setting methods for maximum compatibility
    var cookieStrings = [
      name + '=' + value + ';expires=' + expires.toUTCString() + ';path=/;SameSite=Lax',
      name + '=' + value + ';expires=' + expires.toUTCString() + ';path=/',
      name + '=' + value + ';path=/;max-age=' + (days * 24 * 60 * 60)
    ];
    
    // Try each method
    for (var i = 0; i < cookieStrings.length; i++) {
      document.cookie = cookieStrings[i];
      console.log('[Affiliate Network] Cookie attempt', (i + 1), ':', cookieStrings[i]);
      
      // Verify immediately
      var verify = getCookie(name);
      if (verify === value) {
        console.log('[Affiliate Network] ✅ Cookie verified successfully:', name, '=', verify);
        break;
      } else {
        console.warn('[Affiliate Network] ⚠️ Cookie verification failed for attempt', (i + 1), '- Got:', verify, 'Expected:', value);
      }
    }
    
    // Final verification
    var finalCheck = getCookie(name);
    if (finalCheck === value) {
      console.log('[Affiliate Network] ✅ Cookie successfully set and verified:', name, '=', finalCheck);
    } else {
      console.error('[Affiliate Network] ❌ Cookie setting failed! Final check:', finalCheck, 'Expected:', value);
      console.log('[Affiliate Network] Current document.cookie:', document.cookie);
    }
    
    // Also store in localStorage as backup
    try {
      localStorage.setItem(name, value);
      console.log('[Affiliate Network] Stored in localStorage as backup:', name, '=', value);
    } catch(e) {
      console.error('[Affiliate Network] Failed to set localStorage:', e);
    }
  }
  
  function getUrlParam(name) {
    var urlParams = new URLSearchParams(window.location.search);
    return urlParams.get(name);
  }
  
  // Get referral code from URL
  var ref = getUrlParam('ref') || getUrlParam('affiliate') || getUrlParam('aff');
  
  // Debug logging
  console.log('[Affiliate Network] Script initialized');
  console.log('[Affiliate Network] Current URL:', window.location.href);
  console.log('[Affiliate Network] Current document.cookie:', document.cookie);
  
  if (ref) {
    console.log('[Affiliate Network] ✅ Found ref parameter:', ref);
  } else {
    console.log('[Affiliate Network] ℹ️ No ref parameter found in URL');
  }
  
  // Get existing cookie or tracking cookie
  var affiliateRef = getCookie(COOKIE_NAME) || getCookie(TRACKING_COOKIE);
  
  if (affiliateRef) {
    console.log('[Affiliate Network] ✅ Found existing cookie:', COOKIE_NAME, '=', affiliateRef);
  } else {
    console.log('[Affiliate Network] ℹ️ No existing cookie found');
  }
  
  // If we have a new ref parameter, update cookie
  if (ref) {
    console.log('[Affiliate Network] Setting cookie:', COOKIE_NAME, '=', ref);
    setCookie(COOKIE_NAME, ref, COOKIE_DURATION);
    affiliateRef = ref;
    
    // Wait a moment then verify cookie was set (allows browser to process)
    setTimeout(function() {
      var verifyCookie = getCookie(COOKIE_NAME);
      if (verifyCookie === ref) {
        console.log('[Affiliate Network] ✅ Cookie verified after delay:', verifyCookie);
      } else {
        console.error('[Affiliate Network] ❌ Cookie verification failed after delay!');
        console.error('[Affiliate Network] Expected:', ref, 'Got:', verifyCookie);
        console.error('[Affiliate Network] All cookies:', document.cookie);
        
        // Try localStorage as fallback
        try {
          localStorage.setItem(COOKIE_NAME, ref);
          console.log('[Affiliate Network] ⚠️ Using localStorage as fallback');
        } catch(e) {
          console.error('[Affiliate Network] ❌ localStorage also failed:', e);
        }
      }
    }, 100);
  } else if (affiliateRef) {
    console.log('[Affiliate Network] Using existing cookie:', affiliateRef);
  } else {
    console.log('[Affiliate Network] ℹ️ No affiliate reference available');
  }
  
  // Track click if we have affiliate reference
  // Use ref from URL if available, otherwise use cookie value (affiliateRef)
  var trackingRef = ref || affiliateRef;
  if (trackingRef) {
    var trackingUrl = API_URL + '/api/tracking/click?trackingCode=' + TRACKING_CODE + '&url=' + encodeURIComponent(window.location.href);
    // Always include ref parameter if we have it (from URL or cookie)
    trackingUrl += '&ref=' + encodeURIComponent(trackingRef);
    
    console.log('[Affiliate Network] Tracking click with ref:', trackingRef, '(from', ref ? 'URL' : 'cookie', ')');
    
    // Send tracking request
    if (navigator.sendBeacon) {
      navigator.sendBeacon(trackingUrl);
      console.log('[Affiliate Network] Click tracked via sendBeacon');
    } else {
      var img = new Image();
      img.src = trackingUrl;
      console.log('[Affiliate Network] Click tracked via Image beacon');
    }
  } else {
    console.log('[Affiliate Network] ⚠️ No affiliate reference available for tracking (no ref in URL and no cookie)');
  }
  
  // WooCommerce Integration - Add affiliate data to checkout
  if (typeof jQuery !== 'undefined' && typeof wc_add_to_cart_params !== 'undefined') {
    jQuery(document).ready(function($) {
      var affiliateId = getCookie(COOKIE_NAME) || getCookie(TRACKING_COOKIE);
      
      if (affiliateId) {
        console.log('[Affiliate Network] WooCommerce: Found affiliate ID:', affiliateId);
        
        // Add affiliate data to checkout form
        $(document.body).on('checkout_place_order', function() {
          if (affiliateId) {
            // Add hidden fields to checkout form
            if ($('#affiliate_ref').length === 0) {
              $('<input>').attr({
                type: 'hidden',
                id: 'affiliate_ref',
                name: 'affiliate_ref',
                value: affiliateId
              }).appendTo('form.checkout');
              console.log('[Affiliate Network] Added affiliate_ref to checkout form');
            }
          }
        });
        
        // Also try to set via AJAX for better reliability
        if (typeof wc_checkout_params !== 'undefined') {
          $(document.body).trigger('update_checkout', {
            affiliate_ref: affiliateId
          });
        }
      }
    });
  }
  
  // Generic e-commerce: Store in sessionStorage for later use
  if (typeof sessionStorage !== 'undefined') {
    var storedRef = getCookie(COOKIE_NAME) || getCookie(TRACKING_COOKIE);
    if (storedRef) {
      sessionStorage.setItem('affiliate_ref', storedRef);
    }
  }
  
  console.log('[Affiliate Network] Tracking script loaded successfully');
})();
</script>