Upon completion of an order by a client, the following steps are taken:
- We will retrieve the weighfactors based on the category for each product from a lookup table.
- Calculation will be performed per product using the price, quantity, and weigh factor.
- The sum of all individual product calculations will result in a new conversion value passed on to Google Ads through the conversion pixel.
Instead of relying on the revenue reported by our website, we aim to utilize a different number that more accurately represents the actual sales processed. This adjustment is necessary to enable the use of automated bidding strategies on Google Ads. For example, phones with a 25% acceptance rate may encounter cancellations for some transactions. By assigning a conversion value of €125 per successful sale, we can ensure a more realistic estimation of revenue compared to theoretical values.
To achieve this, we need to implement a new Google pixel on the client's website to communicate the updated conversion value to Google Ads. However, several prerequisites must be met:
- Comprehensive data of the products in shopping baskets during checkout, including SKU, Name, Price, Quantity - A table indicating the weighfactor for each category - JavaScript code capable of calculating the total conversion value based on the price, quantity, and weighfactor for each product in the shopping basket - Integration of a Google Ads conversion pixel to transmit the new conversion value
In the website, there exists a code snippet triggered upon conversion:
The array below is named transactionProducts:
transactionProducts: [
{ Sku: 'dd44', Name: 'tshirt', Category: 'apparel1', Price: 1.99, Quantity: 2, },
{ Sku: 'AA1243544', Name: 'socks', Category: 'apparel2', Price: 9.99, Quantity: 3, }
]
A lookup table assigns conversion factors where apparel1 converts to 0.5 and apparel2 converts to 0.2; Therefore, the final conversion value should be calculated as follows:
2*1.99*0.5 + 3*9.99*0.2 = 1.99 + 5.994 = 7.984
An attempt was made to create JavaScript logic to sum the products in the array. Below is the initial script, seeking assistance due to limited expertise in JavaScript.
function() {
var sum = 0 for (var i = 0; i < {{VAR - transactionProducts}}.length; i++){
sum += {{VAR - transactionProducts}}[i]['quantity']*{{VAR - transactionProducts}}[i]['price']*{{VAR - Datalayer - Pricefactor Category LookupTable}}
};
return sum;
}
The output returned 16.975 which indicates an error somewhere in the calculation process. Upon review, it was discovered that a constant factor of 0.5 was mistakenly applied across all calculations, leading to incorrect results as shown below;
2*1.99*0.5 + 3*9.99*0.5 = 1.99 + 14.985 = 16.975
Identification of the issue points towards the variable used within the Lookup table. While the conversion factor remains consistent ('apparel1' --> 0.5), it should vary based on the specific calculation being conducted.
The input function within the lookuptable is structured as follows;
function() {
for (var i = 0; i < {{VAR - transactionProducts}}.length; i++){
var cat = {{VAR - transactionProducts}}[i]['category']
return cat
};
}
This summarizes the current situation.