Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Last active March 12, 2026 15:46
Show Gist options
  • Select an option

  • Save greenhornet79/e7aadfbb32eed2b4002d496ec45df1af to your computer and use it in GitHub Desktop.

Select an option

Save greenhornet79/e7aadfbb32eed2b4002d496ec45df1af to your computer and use it in GitHub Desktop.
<?php
add_action( 'wp_footer', 'zeen101_add_transaction_event_code' );
function zeen101_add_transaction_event_code() {
if ( ! isset( $_GET['lp_txn_id'] ) ) {
return;
}
$txn_id = absint( $_GET['lp_txn_id'] );
$price = get_post_meta( $txn_id, '_price', true );
$level_id = get_post_meta( $txn_id, '_level_id', true );
$level = get_leaky_paywall_subscription_level( $level_id );
?>
<script>
gtag("event", "purchase", {
transaction_id: "<?php echo $txn_id; ?>",
value: <?php echo $level['price']; ?>,
currency: "USD",
items: [
{
item_id: "<?php echo $level_id; ?>",
item_name: "<?php echo $level['label']; ?>",
affiliation: "Your Publication",
index: 0,
item_brand: "Your Publication",
item_category: "Subscription",
price: <?php echo $level['price']; ?>,
quantity: 1
},
}]
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment