Analytics
1.8K members online now
1.8K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

How to track product purchase price correctly

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello,

 

I have a problem with how I am tracking "Purchase price" custom metric with the transactions.

For "Purchase price" (that is the price i buy product from the supplier) I added a custom product-scoped metric (metric5) with which I send the Purchase price for each product in every "product" object. For security purposes (I dont want the purchase price to be visible in datalayer), it is masked, multiplied by number lets say 79043265917.

 

To unmask the purchase price, I use the formula in calculated metric:

{{Purchase Price}} divided by the same number I multiplied before * {{Quantity}}


Is there any other better and more secure way of doing that?

 

The setup works perfectly for all the orders that include 1 product or 2pcs od the same product, but calculates wrongly if for example there are 2pcs Product A and 2pcs Product B. In that case, the Purchase price is 2x too big, as it calculates it with sum of all quantities.

 

Now I did some testing and found out that the calculation works like this: as {{Purchase Price}} it takes the SUM of all purchase prices for each product in the order, and for {{Quantity}}  it only takes the sum of all quantities. 

 

So for example, if I have in order
2x Product A  with Purchase price 5 EUR each
3x Product B with Purchase price 2 EUR each

 

It will calculate my custom metric like (5+2)*(2+3)
And I would like to calculate it as (2*5)+(3*2)

 

So do you have any Idea how I would assemble a calculated metric like this so this would get calculated correctly with more different  products in the same order?

Thank you very much!!

 

1 Expert replyverified_user

How to track product purchase price correctly

Top Contributor
# 2
Top Contributor

How bout having 2 metrics:

Total product revenue where you calculate the pur.price*qty before masking it and

pur.price for single item and mask it

 

To calculate total for single product you would have calc metric pur.price*quantity

 

--
To make bad day worse, spend it wishing for the impossible

Antti Nylund, Google Analytics Top Contributor
Did my answer solve your issue? If yes, please mark it as the ‘Best Answer.’ Otherwise keep on asking.