PageSourceSearch

https://eriskayconnection.com/wp-content/themes/tecbooks/js/custom.js

js eriskayconnection.com collected 2026-10-02 04:33:24 UTC 8,615 bytes, 249 lines download raw bytes

1console.log("Custom.js is loaded!");
2
3/**
4 * Simple Analytics Event Tracking
5 * 
6 * sa_event() is used to track user interactions and e-commerce events for analytics.
7 * 
8 * WHAT IT DOES:
9 * - Tracks e-commerce events: add to cart, checkout, order completion, etc.
10 * - Sends events to Simple Analytics (privacy-friendly analytics service)
11 * - Helps measure conversion rates, user behavior, and sales performance
12 * 
13 * WHY IT'S NEEDED:
14 * - Track which products are viewed most
15 * - Measure cart abandonment rates
16 * - Monitor checkout funnel performance
17 * - Track order completions and revenue
18 * - Understand user journey through the site
19 * 
20 * If Simple Analytics script is not loaded, this fallback function prevents errors
21 * and optionally logs events to console for debugging.
22 */
23if (typeof sa_event === 'undefined') {
24    window.sa_event = function(eventName, eventData) {
25        // Fallback: Log to console if Simple Analytics isn't loaded
26        console.log('[Simple Analytics] Event:', eventName, eventData || '');
27        // Optionally, you can send to your own analytics endpoint here
28    };
29}
30
31document.addEventListener("DOMContentLoaded", function () {
32    let checkoutButton = document.querySelector(".wc-proceed-to-checkout a.checkout-button");
33    if (checkoutButton) {
34        checkoutButton.addEventListener("click", function () {
35            sa_event("start_checkout");
36        });
37    }
38});
39
40
41function addPlaceOrderListener() {
42    let placeOrderButton = document.querySelector("#place_order");
43    if (placeOrderButton) {
44        placeOrderButton.addEventListener("click", function () {
45            console.log("Place Order button clicked!");
46            sa_event("place_order");
47        });
48        console.log("Event listener added!");
49    } else {
50        console.log("Button not found, retrying...");
51        setTimeout(addPlaceOrderListener, 1000); // Retry every second until it appears
52    }
53}
54
55/*
56document.addEventListener("DOMContentLoaded", function () {
57    document.body.addEventListener("click", function (e) {
58        const button = e.target.closest("button[name='add-to-cart'], .single_add_to_cart_button");
59        if (button) {
60            const productName = document.querySelector(".product_title")?.innerText || "unknown";
61            sa_event("add_to_cart", {
62                product_name: productName
63            });
64            console.log("Add to cart:", productName);
65        }
66    });
67});
68*/
69
70document.body.addEventListener("click", function (e) {
71	const path = window.location.pathname;
72    let target = e.target.closest("button[name='add-to-cart'], .single_add_to_cart_button");
73	
74	const isSingleSlug = path.split("/").filter(Boolean).length === 1;
75
76    if (target && isSingleSlug) {
77		const productName = path.replace("/", "");
78		
79        // Get product name from page or button attribute
80        // let productName = document.querySelector(".product_title")?.innerText || target.dataset.product_name || "Unknown Product";
81
82        // Fire 'add_to_cart' event
83        sa_event("add_to_cart", {
84            product_name: productName
85        });
86        console.log("Add to cart:", productName);
87
88        // Fire 'add_to_cart_session' once per session
89        if (!sessionStorage.getItem("session_add_to_cart")) {
90            sessionStorage.setItem("session_add_to_cart", "true");
91            sa_event("session_add_to_cart");
92            console.log("session_add_to_cart event triggered");
93        }
94    }
95});
96
97
98document.addEventListener("click", function (event) {
99
100	// ORDER & PAYMENT button in Sidecart
101    if (event.target.closest(".vi-wcaio-sidebar-cart-bt-checkout-next")) {
102        console.log("Sidecart ORDER & PAYMENT button clicked!");
103        sa_event("payment_sidecart");
104    }
105
106    // PLACE ORDER button in Sidecart
107    if (event.target.closest(".vi-wcaio-sidebar-cart-bt-checkout-place_order")) {
108        console.log("Sidecart PLACE ORDER button clicked!");
109        sa_event("order_placed_sidecart");
110    }
111
112    // ENTERING the Sidecart
113    if (event.target.closest("#dot")) {
114        console.log("Sidecart opened!");
115        sa_event("go_to_cart");
116    }
117
118    // GOING TO Main Cart
119    if (event.target.closest(".cartMini")) {
120        console.log("Main cart opened!");
121        sa_event("go_to_cart");
122    }
123});
124
125
126function addSidecartCheckoutListener() {
127    let checkoutBtn = document.querySelector(".vi-wcaio-sidebar-cart-bt-nav-checkout");
128    if (checkoutBtn) {
129        checkoutBtn.addEventListener("click", function () {
130            console.log("Sidecart CHECKOUT button clicked!");
131            sa_event("start_checkout");
132        });
133        console.log("Sidecart checkout listener added!");
134    } else {
135        console.log("Sidecart checkout button not found, retrying...");
136        setTimeout(addSidecartCheckoutListener, 1000);
137    }
138}
139
140document.addEventListener("DOMContentLoaded", addSidecartCheckoutListener);
141
142
143document.addEventListener("DOMContentLoaded", function () {
144    const path = window.location.pathname;
145    if (path.startsWith("/checkout/order-received/")) {
146        const orderId = path.split("/")[3]; // Extract order ID from URL
147        if (!sessionStorage.getItem("order_" + orderId)) {
148            console.log("Order received page detected for order ID:", orderId);
149            sa_event("order_received");
150            sessionStorage.setItem("order_" + orderId, true);
151        } else {
152            console.log("Order received already tracked for this order.");
153        }
154    }
155});
156
157/*
158document.addEventListener("DOMContentLoaded", function () {
159    if (!sessionStorage.getItem("sa_session_started")) {
160        sa_event("session_started");
161        sessionStorage.setItem("sa_session_started", "true");
162        console.log("Session started event triggered!");
163    }
164});
165*/
166
167
168document.addEventListener("DOMContentLoaded", function () {
169    const path = window.location.pathname;
170    const nonProductPages = [
171        "forthcoming", "about-us", "cart", "wp-admin", "checkout", 
172        "author", "editions", "wp-login", "themes", "10-books-club",
173		"buy-local", "refund_returns", "random", "my-account",
174		"privacy-policy"
175    ];
176
177    const isSingleSlug = path.split("/").filter(Boolean).length === 1;
178    const isNonProduct = nonProductPages.some(page => path.includes(page));
179
180    if (isSingleSlug && !isNonProduct) {
181        const productName = path.replace("/", "");
182        sa_event("product_viewed", {
183            product_name: productName
184        });
185        console.log("Product viewed:", productName);
186    }
187});
188
189
190/*
191document.addEventListener("DOMContentLoaded", function () {
192    const nonProductPages = [
193        "forthcoming", "about-us", "cart", "wp-admin", "checkout", 
194        "author", "editions", "wp-login", "themes", "10-books-club",
195        "buy-local", "refund_returns", "random", "my-account",
196        "privacy-policy"
197    ];
198
199    document.body.addEventListener("click", function (e) {
200        let target = e.target.closest("a");
201
202        if (target && !target.closest("header") && target.offsetParent !== null) {
203            let url = target.href;
204
205            if (url && url.includes(window.location.hostname)) {
206                let path = new URL(url).pathname;
207
208                // Remove trailing slashes or hashes
209                path = path.replace(/\/(#.*)?$/, "");
210
211                // Ensure it's not a non-product page
212                if (!nonProductPages.some(nonProduct => path.startsWith(nonProduct))) {
213                    sa_event("product_clicked_3", {
214                        link_url: path
215                    });
216                    console.log("Product clicked:", path);
217                }
218            }
219        }
220    });
221});
222*/
223
224
225document.addEventListener("DOMContentLoaded", function () {
226    document.body.addEventListener("click", function (e) {
227        const link = e.target.closest("a");
228        if (link && link.href.includes("/product-tag/")) {
229            sa_event("product_tag_click", {
230                link_url: link.href
231            });
232            console.log("Product tag link clicked:", link.href);
233        }
234    });
235});
236
237/*
238window.addEventListener("beforeunload", function () {
239    sa_event("product_page_load_start");
240});
241*/
242
243/*
244document.addEventListener("visibilitychange", function () {
245    if (document.visibilityState === "visible") {
246        sa_event("product_viewed_2", { product_name: "XYZ" });
247    }
248});
249*/

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.