Created
August 16, 2021 21:33
-
-
Save baumicon/1963427b5dd3c6a3c1f2328a52b35f44 to your computer and use it in GitHub Desktop.
Standard Google Tag Manager Transaction Event tracking with BigCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
window.dataLayer = window.dataLayer || []; | |
var transaction = {}; | |
transaction.transactionProducts = []; | |
function addTrans(orderID, store, total, tax, shipping, city, state, country) { | |
transaction.transactionId = orderID; | |
transaction.transactionAffiliation = store; | |
transaction.transactionTotal = parseFloat(total); | |
transaction.transactionTax = parseFloat(tax); | |
transaction.transactionShipping = parseFloat(shipping); | |
} | |
function addItems(orderID, sku, product, variation, price, quantity) { | |
transaction.transactionProducts.push({ | |
'id': orderID, | |
'sku': sku, | |
'name': product, | |
'category': variation, | |
'price': parseFloat(price), | |
'quantity': quantity | |
}); | |
} | |
function trackTrans() { | |
transaction.event = 'bcTransactionComplete'; | |
dataLayer.push(transaction); | |
} | |
function trackGTMEcommerce() { | |
this._addTrans = addTrans; | |
this._addItem = addItems; | |
this._trackTrans = trackTrans; | |
} | |
var pageTracker = new trackGTMEcommerce(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment