PageSourceSearch

https://sawabank.jp/assets/js/track.js?v=20261006b

js sawabank.jp collected 2026-10-08 09:19:39 UTC 4,633 bytes, 111 lines download raw bytes

1/**
2 * 沢バンクの計測。
3 * GA4が読み込まれていないときは何もしない(gtagの有無で判定)。
4 * 個人を特定する情報は一切送らない。
5 */
6(() => {
7  'use strict';
8  const send = (name, params) => {
9    if (typeof window.gtag !== 'function') return;
10    try { window.gtag('event', name, params || {}); } catch (e) { /* 計測の失敗でページを壊さない */ }
11  };
12
13  // 物件ページで参照できるよう、data属性から情報を拾う
14  const meta = document.getElementById('sb-track');
15  const ctx = meta ? {
16    listing_id: meta.dataset.id || '',
17    pref:       meta.dataset.pref || '',
18    agent:      meta.dataset.agent || '',
19    rel:        meta.dataset.rel || '',
20  } : {};
21
22  document.addEventListener('click', (e) => {
23    const a = e.target.closest('a');
24    if (!a) return;
25    const href = a.getAttribute('href') || '';
26
27    // ① 掲載元へのクリック(この事業で最も重要な行動)
28    if (a.dataset.track === 'agent') {
29      // どこから押されたか(本文か、下部固定か)も残す。導線の改善に使う
30      send('outbound_agent', { ...ctx, link_url: href, place: a.dataset.place || 'body' });
31      return;
32    }
33    // ② 所有者の連絡先
34    if (a.dataset.track === 'owner') {
35      send('owner_contact', { ...ctx, method: a.dataset.method || '' });
36      return;
37    }
38    // ③ 地図のピンから物件へ
39    if (a.classList.contains('pin-card')) {
40      send('map_pin_open', { link_url: href });
41      return;
42    }
43    // ④ メール・電話
44    if (href.startsWith('mailto:')) { send('contact_mail', { location: location.pathname }); return; }
45    if (href.startsWith('tel:'))    { send('contact_tel',  { location: location.pathname }); return; }
46    // ⑤ その他の外部リンク
47    if (/^https?:\/\//.test(href) && !href.includes(location.host)) {
48      send('outbound_other', { link_url: href });
49    }
50  }, { passive: true });
51
52  // ⑥ フォームの送信完了(完了画面に置かれた印を読む)
53  const done = document.getElementById('sb-form-done');
54  if (done) {
55    const f = done.dataset.form || '';
56    send('form_complete', { form: f });
57    // 成果に直結する3つは、GA4でキーイベントに登録しやすいよう独立して送る
58    const key = {
59      register:     'lead_register',      // 希望条件の登録
60      owner_submit: 'lead_listing',       // 所有者からの掲載申込
61      agents:       'lead_listing',       // 掲載会社からの申込
62      sawa_inquiry: 'lead_business',      // 事業者からのデータ相談
63    }[f];
64    if (key) send(key, { form: f });
65  }
66
67  // ⑦ 検索の絞り込み(何で絞られているかを知る)
68  if (location.pathname === '/search.php' && location.search) {
69    const q = new URLSearchParams(location.search);
70    const used = ['pref','city','rel','area','price_max','tags','sort']
71      .filter(k => q.get(k) || q.getAll(k + '[]').length);
72    if (used.length) send('search_filter', { filters: used.join(','), pref: q.get('pref') || '' });
73  }
74})();
75
76/* 都道府県を選び直したら、市町村の選択を解除してすぐ絞り込む */
77(() => {
78  const pref = document.getElementById('f-pref');
79  if (!pref) return;
80  pref.addEventListener('change', () => {
81    const city = document.getElementById('f-city');
82    if (city) city.value = '';
83    const page = document.querySelector('input[name="page"]');
84    if (page) page.value = '1';
85    pref.form && pref.form.submit();
86  });
87})();
88
89/* ナビの第2階層をキーボードでも開けるようにする(マウスはCSSのhoverで動く) */
90(() => {
91  const btns = [...document.querySelectorAll('.nav-btn')];
92  if (!btns.length) return;
93  const closeAll = (except) => btns.forEach(b => {
94    if (b === except) return;
95    b.setAttribute('aria-expanded', 'false');
96    document.getElementById(b.getAttribute('aria-controls'))?.classList.remove('open');
97  });
98  btns.forEach(b => {
99    b.addEventListener('click', (e) => {
100      if (window.matchMedia('(max-width:980px)').matches) return;   // スマホは常時展開
101      e.preventDefault();
102      const sub = document.getElementById(b.getAttribute('aria-controls'));
103      const open = b.getAttribute('aria-expanded') === 'true';
104      closeAll(b);
105      b.setAttribute('aria-expanded', String(!open));
106      sub?.classList.toggle('open', !open);
107    });
108  });
109  document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeAll(); });
110  document.addEventListener('click', (e) => { if (!e.target.closest('.nav-grp')) closeAll(); });
111})();

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.