PageSourceSearch

https://www.tpick.co.kr/js/impression-tracker.js

js tpick.co.kr collected 2026-10-10 00:45:56 UTC 2,478 bytes, 81 lines download raw bytes

1/**
2 * 페이지 노출 추적 스크립트
3 * - 페이지 로드 시 자동으로 노출 기록
4 * - Beacon API 우선 사용 (페이지 이탈 시에도 확실히 전송)
5 * - 폴백으로 이미지 픽셀 사용
6 */
7(function() {
8    'use strict';
9
10    // 설정
11    var config = {
12        endpoint: '/track/pv',
13        pageId: null,
14        pageType: 'post',
15        debug: false
16    };
17
18    // 페이지 데이터 속성에서 설정 읽기
19    function init() {
20        var tracker = document.querySelector('[data-impression-tracker]');
21        if (!tracker) {
22            // 대안: body에서 data 속성 찾기
23            tracker = document.body;
24        }
25
26        if (tracker) {
27            config.pageId = tracker.dataset.pageId || tracker.dataset.postId;
28            config.pageType = tracker.dataset.pageType || 'post';
29        }
30
31        // URL에서 post ID 추출 시도 (/post/123 형태)
32        if (!config.pageId) {
33            var match = window.location.pathname.match(/\/post\/(\d+)/);
34            if (match) {
35                config.pageId = match[1];
36            }
37        }
38
39        if (config.pageId) {
40            trackImpression();
41        } else if (config.debug) {
42            console.log('[ImpressionTracker] No page ID found');
43        }
44    }
45
46    // 노출 추적 실행
47    function trackImpression() {
48        var data = {
49            page_id: config.pageId,
50            page_type: config.pageType
51        };
52
53        // Beacon API 사용 (권장)
54        if (navigator.sendBeacon) {
55            var formData = new FormData();
56            formData.append('page_id', data.page_id);
57            formData.append('page_type', data.page_type);
58
59            var success = navigator.sendBeacon(config.endpoint, formData);
60            if (config.debug) {
61                console.log('[ImpressionTracker] Beacon sent:', success, data);
62            }
63        } else {
64            // 폴백: 이미지 픽셀
65            var img = new Image(1, 1);
66            img.src = config.endpoint + '?p=' + encodeURIComponent(data.page_id) +
67                      '&t=' + encodeURIComponent(data.page_type) +
68                      '&_=' + Date.now();
69            if (config.debug) {
70                console.log('[ImpressionTracker] Pixel sent:', data);
71            }
72        }
73    }
74
75    // DOM 로드 후 실행
76    if (document.readyState === 'loading') {
77        document.addEventListener('DOMContentLoaded', init);
78    } else {
79        init();
80    }
81})();

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.