/* Usage analytics core — the ONE implementation (D5 / T7.10). This existed three times: the creator's copy, the wizard's copy (which had no caller — the button lived on the creator), and the admin console's own reader. Once the creator stopped being an iframe (B7/T7.1) the first two sat in one document as five colliding globals; an unreferenced duplicate is exactly what produced D5. One core now; the pages keep only a thin track() wrapper because page state (the creator's dev-mode pause) belongs to the page. The storage KEYS are unchanged on purpose: everything recorded before this file existed is still readable through it. No field VALUES are ever stored — a field-edit event records the field id, nothing else. Classic script, no modules: exposes window.WPUsage. */ 'use strict'; (function () { var SESSION = 's_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6); function load(key) { try { return JSON.parse(localStorage.getItem(key)) || { events: [] }; } catch (e) { return { events: [] }; } } function save(key, data) { try { localStorage.setItem(key, JSON.stringify(data)); } catch (e) { /* storage unavailable — degrade silently */ } } function track(key, event, detail) { try { var d = load(key); d.events.push({ ts: new Date().toISOString(), session: SESSION, event: event, detail: detail || null }); if (d.events.length > 5000) d.events = d.events.slice(-5000); save(key, d); } catch (e) { /* never let telemetry break the tool it watches */ } } function download(key, prefix) { var blob = new Blob([JSON.stringify(load(key), null, 2)], { type: 'application/json' }); var a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = (prefix || 'wp-usage') + '-' + new Date().toISOString().slice(0, 10) + '.json'; document.body.appendChild(a); a.click(); a.remove(); setTimeout(function () { URL.revokeObjectURL(a.href); }, 1000); } window.WPUsage = { load: load, save: save, track: track, download: download, // The pre-D5 keys, verbatim — continuity of the recorded data is a done-when. KEYS: { creator: 'wp_iwp_analytics_v1', wizard: 'wp_suite_analytics_v1' }, }; })();