我想知道如何在会员新闻“谢谢”页面上添加谷歌跟踪,基本上是在用户支付每月或定期付款之后,然后它将数据发送到谷歌分析,并带有“他们购买的计划的名称” 、“支付金额”和“交易id”。
我得到了这段代码,但它没有触发任何东西,或者这不是正确的代码?我不知道如何调试MemberPress所以我遇到了问题,请任何人帮助...
function echo_mepr_tracking_script() {
if(isset($_GET['membership']) && isset($_GET['trans_num'])) {
$txn = MeprTransaction::get_one_by_trans_num($_GET['trans_num']);
if(isset($txn->id) && $txn->id > 0) {
$trans_id = $txn->id;
$total = $txn->total;
// Update total if recurring
if($txn->subscription_id > 0) {
$sub = new MeprSubscription($txn->subscription_id);
if(isset($sub->id) && $sub->id > 0) {
$trans_id = $sub->id; // Use subscription ID as the payment id for recurring subscriptions
//Trial period?
if($sub->trial) {
$total = $sub->trial_amount;
} else {
$total = $sub->total;
}
}
}
?>
<script>
var fh5coMeprTxnNum = '<?php echo urlencode($trans_id); ?>';
var fh5coMeprTxnAmount = '<?php echo floatval($total); ?>';
fbq('track', 'Purchase', {currency: "USD", value: fh5coMeprTxnAmount});
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': fh5coMeprTxnNum,
'revenue': fh5coMeprTxnAmount
});
ga('ecommerce:send');
alert('yes');
</script>
<?php
}
}
}
add_action('wp_footer', 'echo_mepr_tracking_script');