PageSourceSearch

https://shokz.co.kr/js/tracking/pages/tracking-blog.js?ver=2609221605

js shokz.co.kr collected 2026-09-30 06:28:26 UTC 9,627 bytes, 271 lines download raw bytes

1
2function ga4_blog_view_banner(position,creative_slot,creative_name){
3    window.dataLayer.push({ "event_parameters": null });
4    window.dataLayer.push({
5        "event":"ga4Event",
6        "event_name":"view_banner",
7        "event_parameters":{
8            "creative_slot":creative_slot,
9            "position":position,
10            "creative_name":creative_name,
11        }
12    });
13}
14
15function ga4_blog_select_content(content_type,content_name,button_name){
16    window.dataLayer.push({ "event_parameters": null });
17    window.dataLayer.push({
18        "event":"ga4Event",
19        "event_name":"select_content",
20        "event_parameters":{
21            "content_type":content_type,
22            "content_name":content_name,
23            "button_name":button_name
24        }
25    });
26}
27
28/**
29 * 博客正文同源链接点击(非 /shop/)
30 */
31function ga4_blog_content_link_select_content(linkHref, linkText) {
32    ga4_blog_select_content('keyword', linkHref, linkText);
33}
34
35/**
36 * 博客正文同源商品链接点击(包含 /shop/)
37 */
38function ga4_blog_content_link_select_item(linkHref, linkText) {
39    const itemListId = 'keyword';
40    const itemListName = 'keyword';
41    let itemId = '';
42    let product = null;
43
44    try {
45        const url = new URL(linkHref, window.location.origin);
46        const match = url.pathname.match(/\/shop\/([^/]+)/);
47        itemId = match ? decodeURIComponent(match[1]) : '';
48        if (itemId && window.product_dict && window.product_dict[itemId]) {
49            product = window.product_dict[itemId];
50        }
51    } catch (e) {
52        itemId = '';
53    }
54
55    const phpPriceMap = window.shopItemPagePriceMap || {};
56    const phpItemPrice = (itemId && Object.prototype.hasOwnProperty.call(phpPriceMap, itemId))
57        ? Number(phpPriceMap[itemId] || 0)
58        : 0;
59
60    //兼容新旧版本:新版本规则产品数据从 window.ga4InitData 获取
61    const ga4NewBlogProduct = (window.ga4NewVerProduct||[]).includes(itemId)
62    ? (window.ga4InitData||[]).find(it => String(it.pro_attribute_id) === String(itemId))
63    : null;
64    window.dataLayer.push({ "event_parameters": null });
65    window.dataLayer.push({
66        "event": "ga4Event",
67        "event_name": "select_item",
68        "event_parameters": {
69            "item_list_id": itemListId,
70            "item_list_name": itemListName,
71            "button_name": linkText,
72            "items": [{
73                "item_id": ga4NewBlogProduct ? ga4NewBlogProduct.item_id : ((product && product["id1"]) || itemId || linkHref),
74                "item_name": ga4NewBlogProduct ? ga4NewBlogProduct.item_name : ((product && product["id2"]) || linkText),
75                "index": 1,
76                "discount": ga4NewBlogProduct ? ga4NewBlogProduct.discount : "0",
77                "item_list_id": itemListId,
78                "item_list_name": itemListName,
79                "item_category": ga4NewBlogProduct ? ga4NewBlogProduct.item_category : (product["category"]||null),
80                "item_category2": ga4NewBlogProduct ? ga4NewBlogProduct.item_category2 : (product["category2"]||null),
81                "item_category3": ga4NewBlogProduct ? ga4NewBlogProduct.item_category3 : null,
82                "item_variant": ga4NewBlogProduct ? ga4NewBlogProduct.item_variant : (product["variant"]||null),
83                "item_brand": "SHOKZ",
84                "price": phpItemPrice > 0 ? phpItemPrice : (ga4NewBlogProduct ? ga4NewBlogProduct.price : 0),
85                "quantity": "1",
86                "currency": "KRW"
87            }]
88        }
89    });
90}
91
92/**
93 * 博客正文同源链接点击分发
94 */
95function ga4_blog_content_link_click(linkHref, linkText) {
96    // 过滤以下链接,直接走content埋点,其余走select_item
97    const filterShopPaths = [
98        '/shop/all',
99        '/shop/compare',
100        '/shop/garmin_shokz_challenge'
101    ];
102    let shouldFilter = false;
103    try {
104        const url = new URL(linkHref, window.location.origin);
105        const pathname = url.pathname;
106
107        // /shop/pages/*,/shop/list-*,/shop/type-*
108        if (
109            filterShopPaths.some(p => pathname === p) ||
110            /^\/shop\/pages\//.test(pathname) ||
111            /^\/shop\/list-/.test(pathname) ||
112            /^\/shop\/type-/.test(pathname)
113        ) {
114            shouldFilter = true;
115        }
116    } catch (e) {
117        // fallback: simply leave shouldFilter=false
118    }
119    if (linkHref.indexOf('/shop/') !== -1 && !shouldFilter) {
120        ga4_blog_content_link_select_item(linkHref, linkText);
121        return;
122    }
123    ga4_blog_content_link_select_content(linkHref, linkText);
124}
125
126function ga4_blog_is_same_origin_href(href) {
127    if (!href || href.charAt(0) === '#' || href.indexOf('javascript:') === 0 || href.indexOf('mailto:') === 0 || href.indexOf('tel:') === 0) {
128        return false;
129    }
130    try {
131        const url = new URL(href, window.location.origin);
132        return url.origin === window.location.origin;
133    } catch (e) {
134        return false;
135    }
136}
137
138function ga4_blog_is_image_only_link(anchor) {
139    const $link = $(anchor);
140    if ($link.find('img').length === 0) {
141        return false;
142    }
143    const text = $link.clone().find('script,style').remove().end().children('img').remove().end().text().replace(/\u00a0/g, ' ').trim();
144    return text === '';
145}
146
147function ga4_blog_get_link_text(anchor) {
148    const $link = $(anchor);
149    const text = $link.clone().find('script,style').remove().end().children('img').remove().end().text().replace(/\u00a0/g, ' ').trim();
150    if (text) {
151        return text;
152    }
153    return ($link.attr('title') || '').trim();
154}
155
156function ga4_blog_bind_content_links() {
157    const $container = $('#bo_v_con');
158    if ($container.length === 0) {
159        return;
160    }
161
162    const legacyCampaignLinkIds = {
163        OpenRunPro2: true,
164        openfit2plus: true,
165        '1686552797': true,
166        OpenSwimPro: true,
167        buttom1: true,
168        buttom2: true,
169        buttom3: true,
170        buttom4: true
171    };
172
173    $container.on('click', 'a', function() {
174        const $link = $(this);
175        const href = ($link.attr('href') || '').trim();
176        const linkId = $link.attr('id') || '';
177        if (!ga4_blog_is_same_origin_href(href)) {
178            return;
179        }
180        if (ga4_blog_is_image_only_link(this)) {
181            return;
182        }
183        if (linkId && legacyCampaignLinkIds[linkId]) {
184            return;
185        }
186        if ($link.data('tracking-type')) {
187            return;
188        }
189
190        const linkText = ga4_blog_get_link_text(this);
191        if (!linkText) {
192            return;
193        }
194
195        let absoluteHref = href;
196        try {
197            absoluteHref = new URL(href, window.location.origin).href;
198        } catch (e) {
199            absoluteHref = href;
200        }
201
202        ga4_blog_content_link_click(absoluteHref, linkText);
203    });
204}
205
206
207function ga4_blog_domload_function(){
208
209    let blog_page_list = [];
210    const observer_blog_page = new IntersectionObserver((entries) => {
211        entries.forEach(entry => {
212            if (entry.isIntersecting) {
213                const position      =   $(entry.target).data('tracking-position');
214                const create_name   =   $(entry.target).data('tracking-create-name');
215                const slot          =   $(entry.target).data('tracking-slot');
216                console.log("可视元素",create_name);
217                if(!blog_page_list.includes(create_name)){
218                    blog_page_list.push(create_name);
219                    ga4_blog_view_banner(position,slot,create_name);
220                }
221            }
222        }, {
223            threshold: 0.3,
224            rootMargin: '0px'
225        });
226    });
227    const targetElements_blog_page = document.querySelectorAll('#bo_v #bo_v_atc #ga4_blog_p1,#bo_v #bo_v_atc #ga4_blog_p4,#bo_v #bo_v_atc #ga4_blog_p6');
228    targetElements_blog_page.forEach(element => {
229        observer_blog_page.observe(element);
230    });
231
232
233    $("#blogview #ga4_blog_p2 img,#blogview #ga4_blog_p6 img,#blogview #ga4_blog_p5 img,#blogview #ga4_blog_p7 img").click(function(e){
234        const a = $(this).parent('a');
235        const url = 'https://shokz.co.kr/shop/openfit-pro';
236        const content_type = $(a).data('tracking-type');
237        const content_name = $(a).data('tracking-name');
238        const button_name = $(a).data('tracking-button-name');
239        ga4_blog_select_content(content_type,content_name,button_name);
240    })
241    $("#overlay").click(function(){
242        const content_type = $(this).data('tracking-type');
243        const content_name = $(this).data('tracking-name');
244        const button_name = $(this).data('tracking-button-name');
245        ga4_blog_select_content(content_type,content_name,button_name);
246        $('.ga4_blog_youtu_video').attr("src","https://www.youtube.com/embed/ybNik9D9UNA?si=Iew_7_ZKKv2MFBEj&autoplay=1");
247        $(this).remove();
248    })
249    
250    let sell_bluring = false;
251    window.addEventListener('scroll', function() {
252        if(!sell_bluring && $("#bo_v #bo_v_atc #ga4_blog_p2").length > 0 ){
253            if($("#bo_v #bo_v_atc #ga4_blog_p2").isOnScreenBottomNew()){
254                sell_bluring = true;
255                const position      =   $("#ga4_blog_p2").data('tracking-position');
256                const create_name   =   $("#ga4_blog_p2").data('tracking-create-name');
257                const slot          =   $("#ga4_blog_p2").data('tracking-slot');
258                ga4_blog_view_banner(position,slot,create_name);
259            }
260        }
261    })
262    ga4_blog_bind_content_links();
263
264}
265
266document.addEventListener('DOMContentLoaded', () => {
267    ga4_blog_domload_function();
268});
269
270
271

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.