PageSourceSearch

https://www.goo-net.com/common_v2/js/tags/ga/datalayer_init.js

js goo-net.com collected 2026-10-01 10:28:57 UTC 5,114 bytes, 105 lines download raw bytes

1/* GA4 用 dataLayer 初期化。GTM スニペットより先に読み込む前提 */
2(function () {
3    if (window.__GN_DATALAYER_INITIALIZED__) return;
4    window.__GN_DATALAYER_INITIALIZED__ = true;
5
6    var STORAGE_KEY = 'gn_prev_page_type';
7
8    // URL パターン → page_type 判定 (分析チーム分類表準拠)
9    // 上から順に評価、最初にマッチしたものを採用。マッチなしは 'other'
10    var URL_PATTERNS = [
11        // top
12        [/^\/$/, 'top'],
13        [/^\/usedcar\/?$/, 'top'],
14        [/^\/index_00[1-4]\.html$/, 'top'],
15        [/^\/index_x\.html$/, 'top'],
16        [/^\/ipn\/?(index\.html)?$/, 'top'],
17        [/^\/usedcar\/index-\d+\.html$/, 'top'],
18        // brand-top.html は "メーカー一覧" ページで other (car_list の SEO 静的 URL より先に判定)
19        [/^\/usedcar\/brand-top\.html/, 'other'],
20        // car_list (SEO 静的 URL)
21        [/^\/usedcar\/(brand|bodytype|pref|price|certified|exhaust|option|max|nenshiki|year|distance)[-\/]/, 'car_list'],
22        // car_list (動的)
23        [/^\/php\/search\/summary\.php/, 'car_list'],
24        [/^\/cgi-bin\/fsearch\/goo_used_search(_for_iphone)?\.cgi/, 'car_list'],
25        // car_detail
26        [/^\/php\/search\/(spread|print)\.php/, 'car_detail'],
27        [/^\/usedcar\/spread\//, 'car_detail'],
28        // shop_list
29        [/^\/usedcar_shop\/?$/, 'shop_list'],
30        [/^\/usedcar_shop\/pref-/, 'shop_list'],
31        [/^\/php\/shop\/summary\.php/, 'shop_list'],
32        // shop_detail
33        [/^\/php\/shop\/(stock|user_review|after_service|hdplan|tdrive)/, 'shop_detail'],
34        [/^\/usedcar_shop\/[^/]+\/(detail|stock|tdrive)\.html/, 'shop_detail'],
35        [/^\/goonet\/php\/userreview\//, 'shop_detail'],
36        [/^\/user_review\/[^/]+\/detail\.html/, 'shop_detail'],
37        // form_estimate (OEM /goonet/php/estimate_daihatsu/ 等はマッチしない、.php 境界で cart_ins 等の派生を除外)
38        [/^\/goonet\/php\/estimate\/(cart|cart_tradein|confirm|finish|finish_est_chat)\.php/, 'form_estimate'],
39        [/^\/estimate\/no_data\.html$/, 'form_estimate'],
40        [/^\/ipn\/estimate\/no_data\.html$/, 'form_estimate'],
41        // favorite
42        [/^\/php\/mysearch\/compare_list\.php/, 'favorite']
43    ];
44
45    function inferPageType(path) {
46        for (var i = 0; i < URL_PATTERNS.length; i++) {
47            if (URL_PATTERNS[i][0].test(path)) return URL_PATTERNS[i][1];
48        }
49        return 'other';
50    }
51
52    // 優先順位: window.PAGE_TYPE (テンプレ明示) > URL 判定 > 'other'
53    var pageType = window.PAGE_TYPE || inferPageType(window.location.pathname);
54    // 他スクリプト (来店予約リンクへの page_type 付与等) から参照するためグローバルに露出
55    window.__GN_PAGE_TYPE__ = pageType;
56
57    var stockId = window.STOCK_ID || window.STOCKID || '';
58    var shopId = window.CLIENT_ID || '';
59
60    var prevPageType = '';
61    try {
62        // 自サイトからの遷移時のみ前ページ page_type を継承 (外部再入で古い値を拾わないため)
63        var ref = document.referrer || '';
64        if (ref.indexOf('goo-net.com') > -1 || ref.indexOf('gooworld.jp') > -1) {
65            prevPageType = window.sessionStorage.getItem(STORAGE_KEY) || '';
66        }
67        // iframe 内では sessionStorage を書き換えない (親コンテキストの gn_prev_page_type を汚染しないため)
68        if (window.top === window.self) {
69            window.sessionStorage.setItem(STORAGE_KEY, pageType);
70        }
71    } catch (e) {
72        // sessionStorage ブロック時 (プライベートモード等) は無視
73    }
74
75    // TODO: WebView 判定はアプリ担当者確認後に本実装。暫定 'web'
76    var platform = window.PLATFORM || 'web';
77
78    window.dataLayer = window.dataLayer || [];
79    window.dataLayer.push({
80        page_type: pageType,
81        referrer_page_type: prevPageType,
82        stock_id: String(stockId),
83        shop_id: String(shopId),
84        platform: platform
85    });
86
87    // 来店予約 (goo-reserve.com) 遷移時に page_type=<遷移元> を自動付与。
88    // <a> クリックと window.open の両方を hook する (呼び出し側 10+ ファイルを触らずに済ませるため)
89    document.addEventListener('click', function (e) {
90        var a = e.target && e.target.closest ? e.target.closest('a[href*="goo-reserve.com"]') : null;
91        if (!a) return;
92        if (a.href.indexOf('page_type=') > -1) return;
93        var pt = window.__GN_PAGE_TYPE__ || '';
94        var sep = a.href.indexOf('?') > -1 ? '&' : '?';
95        a.href = a.href + sep + 'page_type=' + encodeURIComponent(pt);
96    }, true);
97    var _origOpen = window.open;
98    window.open = function (url, target, features) {
99        if (url && typeof url === 'string' && url.indexOf('goo-reserve.com') > -1 && url.indexOf('page_type=') === -1) {
100            var sep = url.indexOf('?') > -1 ? '&' : '?';
101            url = url + sep + 'page_type=' + encodeURIComponent(window.__GN_PAGE_TYPE__ || '');
102        }
103        return _origOpen.call(window, url, target, features);
104    };
105})();

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.