PageSourceSearch

https://www.autostraddle.com/wp-content/plugins/autostraddle-subsc…/assets/js/click-tracking.js?ver=1790269122

js autostraddle.com collected 2026-10-01 09:16:25 UTC 2,538 bytes, 68 lines download raw bytes

1/**
2 * Job 3 — Click tracking + popup lifecycle events.
3 *
4 * Listens to clicks on any element inside the popup carrying [data-track]
5 * (primary CTA, secondary CTA, dismiss) and pushes a structured event to
6 * both GTM dataLayer and PostHog. Also tracks popup open/close.
7 *
8 * `adblocker_active` is read from window.__adblockerActive, set by
9 * adblocker-detect.js. If the detection hasn't finished yet (very fast
10 * close), defaults to false.
11 */
12(function () {
13    'use strict';
14
15    function pushEvent(eventName, payload) {
16        var enriched = Object.assign({
17            source: 'subscribe_popup',
18            adblocker_active: !!window.__adblockerActive
19        }, payload || {});
20
21        window.dataLayer = window.dataLayer || [];
22        window.dataLayer.push(Object.assign({ event: eventName }, enriched));
23
24        if (window.posthog && typeof window.posthog.capture === 'function') {
25            window.posthog.capture(eventName, enriched);
26        }
27    }
28
29    // Clicks are native DOM events and bubble natively, so a native
30    // delegated listener works fine here.
31    document.addEventListener('click', function (e) {
32        var el = e.target && e.target.closest ? e.target.closest('[data-track]') : null;
33        if (!el) {
34            return;
35        }
36
37        pushEvent('subscribe_popup_click', {
38            popup_action: el.getAttribute('data-track'), // cta_kill_the_ads | cta_print_magazine | dismiss
39            popup_url: el.href || null
40        });
41    });
42
43    // Popup Maker fires pumAfterOpen / pumAfterClose as jQuery events via
44    // $.trigger(). Those do NOT dispatch native DOM events, so a native
45    // addEventListener never fires for them — they must be bound through
46    // jQuery, which is what the click-vs-open/close discrepancy was. The
47    // events bubble up to document through jQuery's event system.
48    function bindLifecycleEvents($) {
49        $(document).on('pumAfterOpen', function () {
50            pushEvent('subscribe_popup_open', {});
51        });
52        $(document).on('pumAfterClose', function () {
53            pushEvent('subscribe_popup_close', {});
54        });
55    }
56
57    if (window.jQuery) {
58        bindLifecycleEvents(window.jQuery);
59    } else {
60        // Defensive: jQuery is a declared dependency, but if load order ever
61        // changes, retry once the DOM is ready.
62        document.addEventListener('DOMContentLoaded', function () {
63            if (window.jQuery) {
64                bindLifecycleEvents(window.jQuery);
65            }
66        });
67    }
68})();

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.