Skip to content

Instantly share code, notes, and snippets.

@measureschool
Last active August 29, 2024 13:32
Show Gist options
  • Save measureschool/f7d4cfe4e287703c6ba47ae14093e38f to your computer and use it in GitHub Desktop.
Save measureschool/f7d4cfe4e287703c6ba47ae14093e38f to your computer and use it in GitHub Desktop.

MeasureSchool - ThriveCart Ecommerce Events (UA & GA4)

Instructions - ThriveCart

thrivecart

  1. Copy the contents from 01-base-all-pages.html & paste it on All Pages box in the ThriveCart Product Checkout page - Replace GTM-xxxxx with your GTM container ID - Line 12.

  2. Copy the contents from 02-checkout-page.html & paste it on Checkout Page box.

  3. Copy the contents from 03-main-purchase-all-payment-plans-not-bump.html & paste it on both One-time payment & Split pay boxes

<!-- Google Tag Manager -->
<script>
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-xxxxx'); //Replace this with your Container ID
</script>
<!-- End Google Tag Manager -->
<script>
if (_thrive.offer) {
var dataLayer = window.dataLayer || [];
dataLayer.push({
event: _thrive.offer.type,
ecommerce: {
detail: {
products: [
{
name: _thrive.offer.name,
id: _thrive.offer.offer.idx,
price: _thrive.offer.price / 100,
category: _thrive.offer.type,
},
],
},
},
});
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: 'view_item',
ecommerce: {
items: [
{
item_name: _thrive.offer.name,
item_id: _thrive.offer.offer.idx,
price: _thrive.offer.price / 100,
item_category: _thrive.offer.type,
quantity: 1,
},
],
},
});
}
</script>
<script>
var dataLayer = window.dataLayer || [];
var productsArray = [];
var main = {
name: _thrive.product.name,
id: _thrive.product.idx,
category: 'Main',
price: _thrive.product.price,
};
productsArray.push(main);
dataLayer.push({
event: 'eec.detail',
ecommerce: {
detail: {
products: productsArray,
},
},
});
dataLayer.push({ ecommerce: null });
var itemsArray = [];
var itemInfo = {
item_name: _thrive.product.name,
item_id: _thrive.product.idx,
item_category: 'Main',
price: _thrive.product.price,
quantity: 1,
};
itemsArray.push(itemInfo);
dataLayer.push({
event: 'view_item',
ecommerce: {
items: itemsArray,
},
});
</script>
<script>
var products = [];
if (_thrive_order.order.bump) {
var bump = {
name: _thrive_order.order.bump.name,
price: _thrive_order.order.bump.total,
quantity: 1,
};
products.push(bump);
}
if (_thrive_order.order.product) {
var product = {
id: _thrive_order.order.product.id,
name: _thrive_order.order.product.name,
price: _thrive_order.order.product.total,
quantity: 1,
category: 'Main',
};
products.push(product);
}
if (_thrive_order.order.upsells) {
for (keys in _thrive_order.order.upsells) {
var product = {
name: _thrive_order.order.upsells[keys].name,
price: _thrive_order.order.upsells[keys].total,
quantity: 1,
};
products.push(product);
}
}
if (_thrive_order.order.downsells) {
for (keys in _thrive_order.order.downsells) {
var product = {
name: _thrive_order.order.downsells[keys].name,
price: _thrive_order.order.downsells[keys].total,
quantity: 1,
};
products.push(product);
}
}
var dataLayer = window.dataLayer || [];
dataLayer.push({
event: 'eec.purchase',
ecommerce: {
currencyCode: _thrive_order.order.currency,
purchase: {
actionField: {
id: _thrive_order.order.invoice_id,
affiliation: _thrive_order.order.affiliate_id,
revenue: _thrive_order.order.total_readable,
tax: _thrive_order.order.tax_readable,
shipping: _thrive_order.order.shipping,
discount: '0.00',
coupon: '',
},
products: products,
},
},
});
dataLayer.push({ ecommerce: null });
var itemsArray = [];
if (_thrive_order.order.bump) {
var bump = {
item_name: _thrive_order.order.bump.name,
item_id: _thrive_order.order.bump.id,
item_category: 'Bump',
price: _thrive_order.order.bump.total,
quantity: 1,
};
itemsArray.push(bump);
}
if (_thrive_order.order.product) {
var item = {
item_name: _thrive_order.order.product.name,
item_id: _thrive_order.order.product.id,
item_category: 'Main',
price: _thrive_order.order.product.total,
quantity: 1,
};
itemsArray.push(item);
}
if (_thrive_order.order.upsells) {
for (keys in _thrive_order.order.upsells) {
var item = {
item_name: _thrive_order.order.upsells[keys].name,
item_id: _thrive_order.order.upsells[keys].id,
item_category: 'Upsell',
price: _thrive_order.order.upsells[keys].total,
quantity: 1,
};
itemsArray.push(item);
}
}
if (_thrive_order.order.downsells) {
for (keys in _thrive_order.order.downsells) {
var item = {
item_name: _thrive_order.order.downsells[keys].name,
item_id: _thrive_order.order.downsells[keys].id,
item_category: 'Downsell',
price: _thrive_order.order.downsells[keys].total,
quantity: 1,
};
itemsArray.push(item);
}
}
dataLayer.push({
event: 'purchase',
ecommerce: {
currency: _thrive_order.order.currency,
value: _thrive_order.order.total_readable,
tax: _thrive_order.order.tax_readable,
shipping: _thrive_order.order.shipping,
affiliation: _thrive_order.order.affiliate_id,
transaction_id: _thrive_order.order.invoice_id,
coupon: '',
items: itemsArray,
},
});
</script>
{
"exportFormatVersion": 2,
"exportTime": "2024-01-05 02:54:45",
"containerVersion": {
"path": "accounts/144483319/containers/103506100/versions/0",
"accountId": "144483319",
"containerId": "103506100",
"containerVersionId": "0",
"container": {
"path": "accounts/144483319/containers/103506100",
"accountId": "144483319",
"containerId": "103506100",
"name": "ThriveCart GA4",
"publicId": "GTM-PBXL2LJ",
"usageContext": [
"WEB"
],
"fingerprint": "1677573470105",
"tagManagerUrl": "https://tagmanager.google.com/#/container/accounts/144483319/containers/103506100/workspaces?apiLink=container",
"features": {
"supportUserPermissions": true,
"supportEnvironments": true,
"supportWorkspaces": true,
"supportGtagConfigs": false,
"supportBuiltInVariables": true,
"supportClients": false,
"supportFolders": true,
"supportTags": true,
"supportTemplates": true,
"supportTriggers": true,
"supportVariables": true,
"supportVersions": true,
"supportZones": true,
"supportTransformations": false
},
"tagIds": [
"GTM-PBXL2LJ"
]
},
"tag": [
{
"accountId": "144483319",
"containerId": "103506100",
"tagId": "30",
"name": "GA4 - Event - Ecommerce",
"type": "gaawe",
"parameter": [
{
"type": "BOOLEAN",
"key": "sendEcommerceData",
"value": "true"
},
{
"type": "TEMPLATE",
"key": "getEcommerceDataFrom",
"value": "dataLayer"
},
{
"type": "BOOLEAN",
"key": "enhancedUserId",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "eventName",
"value": "{{Event}}"
},
{
"type": "TEMPLATE",
"key": "measurementIdOverride",
"value": "G-XXXXXX"
}
],
"fingerprint": "1704423098108",
"firingTriggerId": [
"29"
],
"parentFolderId": "5",
"tagFiringOption": "ONCE_PER_EVENT",
"monitoringMetadata": {
"type": "MAP"
},
"consentSettings": {
"consentStatus": "NOT_SET"
}
}
],
"trigger": [
{
"accountId": "144483319",
"containerId": "103506100",
"triggerId": "29",
"name": "custom - thrivecart ecommerce event",
"type": "CUSTOM_EVENT",
"customEventFilter": [
{
"type": "MATCH_REGEX",
"parameter": [
{
"type": "TEMPLATE",
"key": "arg0",
"value": "{{_event}}"
},
{
"type": "TEMPLATE",
"key": "arg1",
"value": "(purchase|view_item)"
}
]
}
],
"fingerprint": "1677591941333",
"parentFolderId": "5"
}
],
"variable": [
{
"accountId": "144483319",
"containerId": "103506100",
"variableId": "6",
"name": "dlv - ecommerce.transaction_id",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "ecommerce.transaction_id"
}
],
"fingerprint": "1677573843315",
"parentFolderId": "5",
"formatValue": {}
},
{
"accountId": "144483319",
"containerId": "103506100",
"variableId": "18",
"name": "dlv - ecommerce.value",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "ecommerce.value"
}
],
"fingerprint": "1677573843317",
"parentFolderId": "5",
"formatValue": {}
},
{
"accountId": "144483319",
"containerId": "103506100",
"variableId": "31",
"name": "dlv - ecommerce.currency",
"type": "v",
"parameter": [
{
"type": "INTEGER",
"key": "dataLayerVersion",
"value": "2"
},
{
"type": "BOOLEAN",
"key": "setDefaultValue",
"value": "false"
},
{
"type": "TEMPLATE",
"key": "name",
"value": "ecommerce.currency"
}
],
"fingerprint": "1704423183310",
"parentFolderId": "5",
"formatValue": {}
}
],
"folder": [
{
"accountId": "144483319",
"containerId": "103506100",
"folderId": "5",
"name": "ThriveCart",
"fingerprint": "1677573843315"
}
],
"builtInVariable": [
{
"accountId": "144483319",
"containerId": "103506100",
"type": "EVENT",
"name": "Event"
}
],
"fingerprint": "1704423285812",
"tagManagerUrl": "https://tagmanager.google.com/#/versions/accounts/144483319/containers/103506100/versions/0?apiLink=version"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment