Skip to content

Commit

Permalink
now sending with purchase tag if discount was applied at checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
EfficiencyJunky committed Dec 10, 2020
1 parent 4aefbc2 commit 4b0d1a4
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 43 deletions.
34 changes: 31 additions & 3 deletions guide/06_purchase/01_ss_rawTransactionPush.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,43 @@

// remove any potential PII before pushing to dataLayer
// if the "customer" field exists, reset it to an empty string
if(typeof(ssRawTransaction.billingDetails.customer) != "undefined"){
ssRawTransaction.billingDetails.customer = "";
if(typeof(ssRawTransaction.billingDetails) != "undefined"){
ssRawTransaction.billingDetails["customer"] = "";
}


var discount = {
'status': "not_set",
'amount': 0,
'freeShipping': "not_set"
}

// to figure out if a discount was applied and how much we do the following
// subtract tax, shipping, and subtotal from the grandTotal to get transactionSubtotal
// if the result is less than 0 then a discount was applied
if(typeof(ssRawTransaction.grandTotal) != "undefined"){

var cartSubtotal = ssRawTransaction.subtotal.value
var shippingTotal = ssRawTransaction.shippingTotal.value;
var discountAmount = ssRawTransaction.grandTotal.value
- ssRawTransaction.taxTotal.value
- shippingTotal
- cartSubtotal;

discount = {
'status': (discountAmount < 0) ? "Discount Applied" : "No Discount",
'amount': (discountAmount < 0) ? discountAmount / 100 : 0,
'freeShipping': (shippingTotal == 0) ? "Yes" : "No"
}
}


// push the anonymous transaction information to the dataLayer
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event' : 'ssRawTransactionPush',
'ssRawTransaction': ssRawTransaction
'ssRawTransaction': ssRawTransaction,
'discount': discount
});

</script>
Expand Down
73 changes: 63 additions & 10 deletions guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,22 @@ In Google Analytics, go to settings, and choose the property that will be used f

1. Under "Custom Definitions" choose "Custom Dimensions"

We will need to setup 4 custom dimensions **(Don't worry if the indexes aren't the same as in the pictures):**
We will need to setup these custom dimensions **(Don't worry if the indexes aren't the same as in the pictures):**
* `SS Transaction ID` - Hit Scoped - Value set to the Squarespace alphanumeric transaction ID
* `SS Variant SKU` - Product Scoped - Value set to the Squarespace variant SKU
* `SS Availability` - Product Scoped - Value set to either 'In Stock' or 'Sold Out'
* `SS Sale Status` - Product Scoped - Value set to either 'On Sale' or 'Regular Price'
* `Order Discount Status` - Hit Scoped - Value set to either 'Discount Applied' or 'No Discount'
* `Free Shipping` - Hit Scoped - Value set to either 'Yes' or 'No'

<img src="../img/01--GA_Setup/01--Settings--Property--custom_dimensions.png" height=300>


2. Under "Custom Definitions" choose "Custom Metrics"

We will need to setup 1 custom metric:
We will need to setup these custom metrics:
* `Cart Value` - Product Scoped - Currency (Decimal)
* `Order Discount Amount` - Hit Scoped - Currency (Decimal)

<img src="../img/01--GA_Setup/02--Settings--Property--custom_metrics.png">

Expand Down Expand Up @@ -282,24 +285,39 @@ For more information on variable versions and recursive merge when pushing to da
Data Layer Variable Name: `checkoutTagInfo.totalValue`<br/>
Data Layer Version: Version 2<br/>

11. Variable Name: `DL - EEC Purchase - Order ID`<br/>
11. Variable Name: `DL - SS Raw Transaction`<br/>
Variable Type: Data Layer Variable<br/>
Data Layer Variable Name: `ssRawTransaction`<br/>
Data Layer Version: Version 2<br/>

12. Variable Name: `DL - EEC Purchase - Order ID`<br/>
Variable Type: Data Layer Variable<br/>
Data Layer Variable Name: `ssRawTransaction.orderNumber`<br/>
Data Layer Version: Version 2<br/>

12. Variable Name: `DL - EEC Purchase - Revenue`<br/>
13. Variable Name: `DL - EEC Purchase - Revenue`<br/>
Variable Type: Data Layer Variable<br/>
Data Layer Variable Name: `ssRawTransaction.grandTotal.decimalValue`<br/>
Data Layer Version: Version 2<br/>

13. Variable Name: `DL - EEC Purchase - SS Transaction ID`<br/>
14. Variable Name: `DL - EEC Purchase - SS Transaction ID`<br/>
Variable Type: Data Layer Variable<br/>
Data Layer Variable Name: `ssRawTransaction.id`<br/>
Data Layer Version: Version 2<br/>

14. Variable Name: `DL - SS Raw Transaction`<br/>
15. Variable Name: `DL - EEC Purchase - Discount Status`<br/>
Variable Type: Data Layer Variable<br/>
Data Layer Variable Name: `ssRawTransaction`<br/>
Data Layer Variable Name: `discount.status`<br/>
Data Layer Version: Version 2<br/>

16. Variable Name: `DL - EEC Purchase - Discount Amount`<br/>
Variable Type: Data Layer Variable<br/>
Data Layer Variable Name: `discount.amount`<br/>
Data Layer Version: Version 2<br/>

17. Variable Name: `DL - EEC Purchase - Free Shipping`<br/>
Variable Type: Data Layer Variable<br/>
Data Layer Variable Name: `discount.freeShipping`<br/>
Data Layer Version: Version 2<br/>

---
Expand Down Expand Up @@ -418,7 +436,7 @@ A quick note before getting started. The tag configuration I've outlined below i

The parts that actually HAVE to be followed exactly are: "Enhanced Ecommerce Features" needs to be set to true, "Read Data from Variable" needs to be set to the variable indicated, and the "Trigger" needs to be choosen as indicated.

The process for each of these will be the same:<br/>
The process for each of these will be the same **EXCEPT FOR THE "PURCHASE" TAG WHICH HAS ADDITIONAL CUSTOM DIMENSIONS AND METRICS**<br/>

1. from the "Tags" page in GTM choose "New"
2. give it the name specified by "Tag Name"
Expand Down Expand Up @@ -497,15 +515,19 @@ The process for each of these will be the same:<br/>
* Value: `{{DL - EEC Purchase - Revenue}}`
* Non-Interactioin Hit: `True`
* Enable overriding settings in this tag
* Custom Dimensions:
* Index `4` - Dimension Value: `{{DL - EEC Purchase - SS Transaction ID}}`
* Index `8` - Dimension Value: `{{DL - EEC Purchase - Discount Status}}`
* Index `9` - Dimension Value: `{{DL - EEC Purchase - Free Shipping}}`
* Custom Metrics:
* Index `2` - Metric Value: `{{DL - EEC Purchase - Discount Amount}}`
* More Settings -> Ecommerce:
* Enable Enhanced Ecommerce Features: `True`
* Read Data from Variable: `{{JS - eec.purchase}}`
* Trigger: `custom event - ssRawTransactionPush`





---
# SECTION 8 -- CELEBRATE...NO WAIT...TEST EVERYTHING FIRST!!!
Congratulations on making it through. Now the entire implementation needs to be tested. Go through the entire user journey and make sure to trigger each Tag. The testing process should be something like this
Expand All @@ -526,3 +548,34 @@ Congratulations on making it through. Now the entire implementation needs to be





<!--
ADD ONS
GOOGLE ANALYTICS CUSTOM DIMENSIONS / METRICS
Dimensions:
* Order Discount Status
* Free Shipping
Metrics:
* Order Discount Amount
RAW TRANSACTION DATALAYER PUSH
var discount = {
'status': "not_set",
'amount': 0,
'freeShipping': "not_set"
}
GTM DL VARIABLES
DL - EEC Purchase - Discount Status -> discount.status
DL - EEC Purchase - Discount Amount -> discount.amount
DL - EEC Purchase - Free Shipping -> discount.freeShipping
TAG MODIFICATION
Add Custom Dimensions / Metric to Purchase tag
-->
152 changes: 122 additions & 30 deletions reference/ss_objects/06_purchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,6 @@ var purchaseCompletePageScriptContents = {
































var purchaseCompletePageScriptContents = {
id: '5fb734bc1b54d22df157f49a',
orderNumber: '12439',
Expand Down Expand Up @@ -99,4 +70,125 @@ var purchaseCompletePageScriptContents = {
quantity: 1
}
]
}
}



// squarespace doesn't indicate if a coupon was used on checkout
// but squarespace DOES offer coupons for a single product or as a discount on the entire order
// we can detect if a coupon was used by comparing the grandTotal minus tax and shipping to the subtotal
var purchaseWithCoupon = {
id: '5fd27f976284eb75bb6d12d1',
orderNumber: '00005',
websiteId: '5c04a037c258b4c112b25fdb',
purchasedCartId: '5fd27f2810bb3b6da580c616',
testMode: true,
grandTotal: {
currencyCode: 'USD',
"value": 1720,
decimalValue: '17.20',
fractionalDigits: 2
},
grandTotalFormatted: '$16.00',
subtotal: {
currencyCode: 'USD',
"value": 1500,
decimalValue: '15.00',
fractionalDigits: 2
},
subtotalFormatted: '$15.00',
taxTotal: {
currencyCode: 'USD',
"value": 120,
decimalValue: '1.20',
fractionalDigits: 2
},
taxTotalFormatted: '$1.20',
shippingTotal: {
currencyCode: 'USD',
"value": 300,
decimalValue: '3.00',
fractionalDigits: 2
},
shippingTotalFormatted: '$3.00',
billingDetails: {customer: ''},
items: [
{
sku: 'SQ8858424',
productName: 'regular price unlimited stock product',
unitPrice: {
currencyCode: 'USD',
value: 500,
decimalValue: '5.00',
fractionalDigits: 2
},
quantity: 2
},
{
sku: 'SQ6738738',
productName: '12/24V and USB Power Switcher',
unitPrice: {
currencyCode: 'USD',
value: 500,
decimalValue: '5.00',
fractionalDigits: 2
},
quantity: 1
}
]
}






var priceWithTax = {
id: '5fd28bbd4e3b216e6e62d3bd',
orderNumber: '00006',
websiteId: '5c04a037c258b4c112b25fdb',
purchasedCartId: '5fd284333497c1706a4fe084',
testMode: true,
grandTotal: {
currencyCode: 'USD',
value: 858,
decimalValue: '8.58',
fractionalDigits: 2
},
grandTotalFormatted: '$8.58',
subtotal: {
currencyCode: 'USD',
value: 500,
decimalValue: '5.00',
fractionalDigits: 2
},
subtotalFormatted: '$5.00',
taxTotal: {
currencyCode: 'USD',
value: 58,
decimalValue: '0.58',
fractionalDigits: 2
},
taxTotalFormatted: '$0.58',
shippingTotal: {
currencyCode: 'USD',
value: 300,
decimalValue: '3.00',
fractionalDigits: 2
},
shippingTotalFormatted: '$3.00',
billingDetails: {customer: ''},
items: [
{
sku: 'SQ8858424',
productName: 'regular price unlimited stock product',
unitPrice: {
currencyCode: 'USD',
value: 500,
decimalValue: '5.00',
fractionalDigits: 2
},
quantity: 1
}
]
}

1 comment on commit 4b0d1a4

@EfficiencyJunky
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolves issue #7

Please sign in to comment.