[请益] javascript 放进php中

楼主: seft584f8 (seft584f8)   2018-11-13 03:32:48
知道GA 的 javascript tracking code应该放在HTML
但因为遇到的状况是只能确定我要侦测的动作出现在某个php function
所以想来想去、查来查去,似乎只能试着把GA tracking code放到php function内
可是我试了两天都无效果,可否有经验的人可以给建议
我的code如下:
//以下为php function, 存于某file.php
function confirm_order($order, $comments) {
echo"
<script language='javascript'>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'fb_pixel_id'); // Insert your pixel ID here.
fbq('track', 'Purchase');
</script>";
echo "
<script language='javascript'>
function gtag_report_conversion(url) {
var callback = function () {
if (typeof(url) != 'undefined') {
window.location = url;
}
};
gtag('event', 'conversion', {
'send_to': 'google_ads_id/dXgxCNDAlI0BELywjPQC',
'transaction_id': '',
'event_callback': callback
});
return false;
}
</script> ";
}

Links booklink

Contact Us: admin [ a t ] ucptt.com