Support

Home Forums Event Espresso Premium Google Tag Manager Dynamic Price for Purchase Event

Google Tag Manager Dynamic Price for Purchase Event

Posted: June 1, 2020 at 8:51 pm


Jarred

June 1, 2020 at 8:51 pm

I was reading this post and it’s awesome https://eventespresso.com/topic/push-conversion-event-to-datalayer/

But how can I make the price dynamically fill on a purchase conversion?

Would the code Josh placed on that post listed above be able to append the code from this facebook post? https://www.facebook.com/business/help/262326191335941

Basically I want the purchase event to fire and tell Facebook the total price of the cart AND/OR the total of the items bought.

But if only one way would work, the total value of the cart on Event Espresso would be great to send with the FB Purchase Pixel Event firing on Google Tag Manager.


Tony

  • Support Staff

June 2, 2020 at 8:24 am

Hi Jarred,

The hook used with that snippet is passed the EE_Transaction object so you have access to pretty much everything you need through our model system:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

$transaction->total(); will give you the transaction total.

When you say ‘items bought’ do you just need the number of tickets selected in total?


Jarred

June 2, 2020 at 12:33 pm

I have a Custom HTML container and using the code Josh gave me I can see value now for the ticket price. But how can I implement the PHP that you mentioned for Transaction Total?

Basically i just need the transaction total to be sent with the Purchase fired tag so fb has a value of the conversion.
Im using this script as a tag and it pulls the WooCommerce transaction total so how can I make EE send the transaction total just like the Woo did?

I have this now:
it will bring the currency: USD but it wont bring in the value. https://www.screencast.com/t/h9HM1zCOtYVF

///////////////////
add_action(
‘AHEE__thank_you_page_overview_template__top’,
‘example_code_function’
);
function example_code_function($transaction) {
if ( $transaction instanceof EE_Transaction ) {
?>
<script type=”text/javascript”>
jQuery(document).ready(function($) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
‘event’ : ‘eventRegistration’,
‘value’ : ‘<?php echo $transaction->total->get(‘TXN_total’); ?>’
});
});
</script>
<?php
}
}
/////////////////////////////////////////

and for my fb script I have vale has dlv-transactionTotal because I made it a data layer variable for transactionTotal.
<script>
fbq(‘track’, ‘Purchase’, {
value: {{dlv- transactionTotal}},
currency: ‘USD’,
});
</script>

What PHP do I need to pull the Event espresso Transaction total?
Using Josh code I see eventregistration now
https://www.screencast.com/t/uYoRghFiVyaS

Shows this data layer after message
https://www.screencast.com/t/RkZbBdoFhT


Jarred

June 3, 2020 at 12:00 am

I was able to fire the correct trigger for GTM using the code from Josh’s old post by using a “Custom Event” as the trigger instead of pageview.

http://prntscr.com/ssrx97
http://prntscr.com/ssry9y
http://prntscr.com/sss30q

If curious where I got the {{Espresso Value}} seen in image, its a user-defined data layer variable I created to pull in the value (total cost) of event espresso thank you page. SO it give full total. http://prntscr.com/ssrzcn

=====================================

Now I’m trying to do Google Analytics event and have the sales show up on the Enhanced Ecommerce sale report.

I was able to get the Event to fire on google analytics BUT, it wont pull in the value for some reason.

Is there a way to have Event Espresso Transaction ID and a way to have the Event Name (name of the class or camp they bought) in the data layer so I can include it with ‘eventRegistration’ ?

I don’t know the PHP language but I think what I’m asking is this:

include the following items with ‘eventRegistration’ in the data layer so that when I call on eventRegistration to trigger a tag firing it will include these items.

Currency: (already have by writing manually)
Value: (I have this setup already from code from Josh above)
Event Name Title/Class Name Title (?)
Transaction ID (invoice or receipt# and how to display it on thank you page)
Date

Thanks


Tony

  • Support Staff

June 5, 2020 at 4:37 am

In Josh’s example, you have the EE_Transaction object within $transaction which means you have pretty much any data you need.

I’m assuming you already know JavaScript so you know how to add additional values to the dataLayer, correct?

So I can show you how to pull the values you are requesting, but some some aren’t as clean cut as they seem.

Currency: (already have by writing manually)

You don’t need to hardcode the currency, you can pull it from the EE_Registry:

EE_Registry::instance()->CFG->currency->code;

So, something like:

'currency' : '<?php echo EE_Registry::instance()->CFG->currency->code; ?>'

Value: (I have this setup already from code from Josh above)

You already have this, but imo, ‘value’ is a misleading variable name here. I’d recommend changing it to something like ‘transactionTotal’.

Reason being in x months when you view this code back and think ‘Value? Value of what?’ it’s not obvious without going through the code, ‘transactionTotal’ is.

Event Name Title/Class Name Title (?)

Event Name isn’t as simple here because a transaction can be have multiple registrations within them and if using the Multi Event Registration Add-on any/each/all of those registrations could be for different events.

The simplest way to pull a single event name is to use the ‘Primary Registration’ and pull the details/event linked to that. So at the top of Josh’s function add something like:

$event_name = 'Unknown';
$primary_reg = $transaction->primary_registration();
if ($primary_reg instanceof EE_Registration) {
    $event = $primary_reg->event();
    if ($event instanceof EE_Event) {
        $event_name = $event->name();
    }
}

Then in the JavaScript you can use $event_name:

‘eventName’ : ‘<?php echo $event_name; ?>’

Transaction ID (invoice or receipt# and how to display it on thank you page)

You already have the transaction object, so $transaction->ID(); will give you the ID.

Date

Date? Today’s date? Transaction date? (They may not match depend on what you are doing so you need to be specific here)

Transaction date can be pulled in using $transaction->datetime(true);

Is that what you are looking for?

(Note all of the above is untested and hand written)

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3 Documentation for Event Espresso 4

Status: publish

Updated by  Tony 1 month ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!