When a transaction is processed, we pass a JavaScript object to the page that contains easily accessibly transaction data to be used with third party tracking and analytics services such as Google Analytics.
The Transaction object contains the following (sample data displayed):
<script>
QGIV.Transaction = {
id : '12345', // ID - string
date : '2015-10-21 16:29:00', // date and time - string
status : 'Accepted', // status - string - "Accepted" or "Declined"
demo : false, // demo transaction - boolean
timestamp : 1445459340, // timestamp - Unix timestamp
info : 'abc', // associated info - string
form : 'My Form Name', // form name - string
total : '121.00', // transaction total - string
firstName : 'Emmett', // donor first name - string
lastName : 'Brown', // donor last name - string
company : 'Dr. E. Brown Enterprises', // donor company - string
address : '1640 Riverside Drive', // donor address - string
city : 'Hill Valley', // donor city - string
state : 'CA', // donor state - string
zip : '12345', // donor zip code - string
country : 'US', // donor country - US
email : 'ebrown@example.com', // donor email address - string
optIn : 'y', // opt in - string - "y" or "n"
anonymous : 'n', // anonymous - "y" or "n"
billingAddress : '1640 Riverside Drive', // donor billing address - string
billingCity : 'Hill Valley', // donor billing city - string
billingState : 'CA', // donor billing state - string
billingZip : '12345', // donor billing zip - string
billingCountry : 'US', // donor billing country - string
info : 'CampaignABC' // associated info
// if it's a recurring transaction, the following data will be included
recurring : {
amount : '100.00', // recurring amount - string
firstBill : '2023-01-01', // first bill date - string
finalBill : '2023-12-01', // final bill data - string
frequency : '1', // frequency - string
frequencyUnit : "month", // frequency unit - string
frequencyDescription : "Monthly" // frequency description - string
}
};
</script>
You can access the data in your code snippet by referencing the object directly. The example below shows how to access the total transaction amount:
QGIV.Transaction.total
To prevent accuracy issues when someone visits their receipt, the Transaction object is only available when a transaction initially processes. To ensure that your code snippet works properly with the Transaction object, you should conditionally execute your code only if the Transaction object is present.
Here's an example that illustrates how to properly utilize this with Google eCommerce:
<script>
ga('create', 'UA-XXXXXX-XX', 'auto');
ga('send', 'pageview');
if ( typeof QGIV.Transaction !== 'undefined' ){
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id' : QGIV.Transaction.id,
'affiliation' : QGIV.Transaction.form,
'revenue' : QGIV.Transaction.total
});
ga('ecommerce:send');
}
</script>
Here's an example that illustrates how this can be used with Facebook Pixels. The following code should be placed after the main pixel code:
<script>
if ( typeof QGIV.Transaction !== 'undefined' ) {
fbq('track', 'Purchase', {value: QGIV.Transaction.total, currency: 'USD'});
}
</script>