(async function(){ if (!window.cj) window.cj = {}; if (! cj_from_php.post_id){ cj_from_php.post_id = ''; } else if (isNaN(cj_from_php.post_id) || +cj_from_php.post_id < 1){ throw Error('Failed to add CJ Affiliate Tracking code due to receiving the invalid post ID: ' + cj_from_php.post_id) } let use_conversion_tag = cj_from_php.tag_type === 'conversion_tag' let action = use_conversion_tag ? 'cj_conversion_tag_data' : 'cj_site_tag_data' let url = cj_from_php.ajaxurl + '?action=' + action + '&post_id=' + cj_from_php.post_id if (use_conversion_tag){ url += '&order-received=' + cj_from_php.woo_order_id } let resp = await fetch(url) if ( ! resp.ok) throw Error('Error retrieving tag data') let data = await resp.json() // Extract source data from the combined response let source_data = data.source delete data.source let cj_prop = use_conversion_tag ? 'order' : 'sitePage' window.cj[cj_prop] = data window.cj.source = source_data let script = document.createElement('script'); script.src = 'https://www.mczbf.com/tags/' + cj_from_php.tag_id + '/tag.js'; script.type = 'text/javascript'; script.async = true; script.id = 'cjapitag'; document.getElementsByTagName('script')[0].parentNode.insertBefore(script, document.getElementsByTagName('script')[0]) })();