
    (async function ({ tag, tagDisp, functionUrl, }) {
    const ytag = document.createElement('script');
    ytag.setAttribute('src', 'https://s.yimg.jp/images/listing/tool/cv/ytag.js');
    document.body.appendChild(ytag);
    const gtag = document.createElement('script');
    gtag.innerHTML = `
    window.yjDataLayer = window.yjDataLayer || [];
    function ytag() { yjDataLayer.push(arguments); }
    ytag({"type":"ycl_cookie"});
  `;
    document.body.appendChild(gtag);
    const Shopify = window.Shopify;
    const ShopifyAnalytics = window
        .ShopifyAnalytics;
    if (tag) {
        const adTag = document.createElement('script');
        adTag.innerHTML = tag;
        document.body.appendChild(adTag);
    }
    if (tagDisp) {
        const getPageInfo = async () => {
            var _a, _b, _c, _d, _e, _f;
            if (window.location.pathname === '/') {
                return { pageType: 'home', productIds: [] };
            }
            else if (window.location.pathname.startsWith('/collections')) {
                return {
                    pageType: 'category',
                    productIds: ((_b = (_a = ShopifyAnalytics === null || ShopifyAnalytics === void 0 ? void 0 : ShopifyAnalytics.meta) === null || _a === void 0 ? void 0 : _a.products) === null || _b === void 0 ? void 0 : _b.map((product) => product.id)) || [],
                };
            }
            else if (window.location.pathname.startsWith('/search')) {
                return { pageType: 'search', productIds: [] };
            }
            else if (window.location.pathname.startsWith('/products')) {
                return {
                    pageType: 'detail',
                    productIds: ((_d = (_c = ShopifyAnalytics === null || ShopifyAnalytics === void 0 ? void 0 : ShopifyAnalytics.meta) === null || _c === void 0 ? void 0 : _c.product) === null || _d === void 0 ? void 0 : _d.id) ? [(_f = (_e = ShopifyAnalytics === null || ShopifyAnalytics === void 0 ? void 0 : ShopifyAnalytics.meta) === null || _e === void 0 ? void 0 : _e.product) === null || _f === void 0 ? void 0 : _f.id] : [],
                };
            }
            else if (window.location.pathname.startsWith('/cart')) {
                let variantIds = [];
                document.querySelectorAll('a[href*="variant="]').forEach((element) => {
                    var _a;
                    const variantId = (_a = element.getAttribute('href')) === null || _a === void 0 ? void 0 : _a.split('variant=')[1];
                    variantId && variantIds.push(variantId);
                });
                if (variantIds.length === 0) {
                    return { pageType: 'cart', productIds: [] };
                }
                try {
                    const res = await fetch(`${functionUrl}/getProductIds?shopId=${Shopify.shop}&variantIds=${Array.from(new Set(variantIds)).join(',')}`);
                    if (!res.ok) {
                        throw new Error('Bad fetch response');
                    }
                    const data = await res.json();
                    return { pageType: 'cart', productIds: data.productIds };
                }
                catch (e) {
                    return { pageType: 'cart', productIds: [] };
                }
            }
            else if (window.location.pathname.startsWith('/checkouts')) {
                return { pageType: 'conversionintent', productIds: [] };
            }
            else {
                return { pageType: '', productIds: [] };
            }
        };
        const { pageType, productIds } = await getPageInfo();
        const adTagDisp = document.createElement('script');
        adTagDisp.innerHTML = tagDisp
            .replace("'yahoo_retargeting_page_type': ''", `'yahoo_retargeting_page_type': '${pageType}'`)
            .replace("{item_id: '', category_id: '', price: '', quantity: ''}", productIds.length === 0
            ? "{item_id: '', category_id: '', price: '', quantity: ''}"
            : productIds
                .map((productId) => `{item_id: '${productId}', category_id: '', price: '', quantity: ''}`)
                .join(', '));
        document.body.appendChild(adTagDisp);
    }
})
    ({
      tag: `


ytag({
  'type':'yss_retargeting',
  'config': {
    'yahoo_ss_retargeting_id': '1001367743',
    'yahoo_sstag_custom_params': {
    }
  }
});
`, 
      tagDisp: `


ytag({
  'type':'yjad_retargeting',
  'config':{
    'yahoo_retargeting_id': 'A0QH0FSR6K',
    'yahoo_retargeting_label': '',
    'yahoo_retargeting_page_type': '',
    'yahoo_retargeting_items':[
      {item_id: '', category_id: '', price: '', quantity: ''}
    ]
  }
});
`, 
      functionUrl: `https://asia-northeast1-ydn-pr.cloudfunctions.net`
    })