GA4 purchase event revenue not matching order value - shopify

The purchase event on shopify purchases is showing revenue values that are close but do not match the purchase value. The event value appears correct, but ecommerce revenue seems to be changing the value a small amount.
Any ideas on a fix?
The 60 event value is what it should be.
Data Layer purchase event:
/** DATALAYER: Checkout on Shopify Plus **/
if(Shopify.Checkout){
var ecommerce = {
'transaction_id': '{{checkout.order_number | json}}',
'affiliation': {{shop.name | json}},
'value': {{checkout.total_price | money_without_currency | replace: ',', '.' | json}},
'tax': {{checkout.tax_price | money_without_currency | replace: ',','.' | json}},
'shipping': {{checkout.shipping_price | money_without_currency | replace: ',','.' | json}},
'subtotal': {{checkout.subtotal_price | money_without_currency| replace: ',','.' | json}},
'currency': {{checkout.currency | json}},
{% for discount in checkout.discounts %}
'coupon': {{discount.code | json}},
'discount' : {{discount.amount | money_without_currency | json}},
{% endfor %}
'email': {{checkout.email | json}},
'items':[{% for line_item in checkout.line_items %}{
'item_id' : '{{line_item.product.id | json}}',
'item_variant' : {{line_item.variant.title | json}},
'item_name' : {{line_item.product.title | json}},
'price' : {{line_item.product.price | money_without_currency | replace: ',', '.' | json}},
'item_brand' : {{line_item.product.vendor | json}},
'item_category' : {{line_item.product.type | json}},
'item_list_name' : {{line_item.collection.title | json}},
'quantity' : {{line_item.quantity | json}},
'discount' : {{discount.code | json}}
},{% endfor %}],
};
if(Shopify.Checkout.step){
if(Shopify.Checkout.step.length > 0){
if (Shopify.Checkout.step === 'contact_information'){
dataLayer.push({
'event' :'begin_checkout',
'pageType' :'Customer Information',
'step': 1,
ecommerce
});
}else if (Shopify.Checkout.step === 'shipping_method'){
dataLayer.push({
'event' :'add_shipping_info',
'pageType' :'Shipping Information',
ecommerce
});
}else if( Shopify.Checkout.step === "payment_method" ){
dataLayer.push({
'event' :'add_payment_info',
'pageType' :'Add Payment Info',
ecommerce
});
}
}
/** DATALAYER: Transaction */
if(Shopify.Checkout.page == "thank_you"){
dataLayer.push({
'pageType' :'Transaction',
'event' :'purchase',
ecommerce
});
}
}
}
I've tested in tag assistant and the values on the order are as expected in the data layer.
But using the ecommerce metrics in GA4, something is changing the values slightly.
Currency matches in GA4, dataLayer & shopify.
Thinking it could be something to do with this:
{{checkout.total_price | money_without_currency | replace: ',', '.' | json}}
Any help or resources appreciated!

According to https://support.google.com/analytics/answer/9796179?hl=en#zippy=%2Cin-this-article
Even if the currency setting for your property or view is set to match your local currency, Analytics performs a conversion at the moment of processing a hit for non-USD currencies and a fresh conversion on that figure each time a report is generated. This can lead to very small differences in your reports for your local currency due to fluctuations in the daily exchange rate.

Related

using a variable for size of image in img_url in liquid

I am trying to display an image in my shopify store with an aspect ratio of 4:1, but because I cannot know to image's size I am using the following code:
{% assign h = image_object.width | divided_by: 4 %}
{% assign size = image_object.width | append: "x" | append: h | strip %}
<img src="{{ image_object | img_url: size ,crop: 'center'}}">
but this doesn't work. The image stays in its original size.
The problem was that divided_by was returning a non-integer number which doesn't work with img_url. adding | floor solved the problem.

Shopify product.price.liquid Math Filters not displayed correct

I've added some code in the product.price.liquid to make a simple math formula:
<span id="extrainfo">
<span id="perkg">{{ variant.price | times: 100.0 | divided_by: variant.weight | money }}</span>/100g
</span>
Whole Code of the liquid here
Result: On the Product detail page, the result of the math formula is shown right=> Detail Page, but on the collections page or homepage, there comes "Inf"=> Collection Page
Any Ideas?
The last | money parameter might be confusing. Try like this
{% assign variant_price = variant.price | times: 100.0 %}
{% assign variant_price = variant_price | divided_by: variant.weight %}
{% assign variant_price | money %}
{{ variant_price }}

Linq-like group by for sql

It seems like sql group by is more of aggregate functions (COUNT, MAX, MIN, SUM, AVG).
select count(Id), Country
from Customer
where Country <> 'CountryX'
group by Country
But do we have a linq-like query where we want to return all results grouped by a certain column, E.g. in linq I would do
id | title | category | email
------------------------------------------
1 | tname-1 | cat1 | test#example.com
2 | tname-2 | cat1 | test1#example.com
3 | tname-3 | cat2 | TEst#example.com
linq group-by:
var groupedBy = list.GroupBy(item => item.Email);
or even throw in some comparison
var groupedBy = list.GroupBy(item => item.Email, StringComparer.OrdinalIgnoreCase);
and a result will be something like:
key | items
----------------------------------------------------------------------------------------------
test#example.com | [{Id :1, Title : "tname-1", category: "cat1", email: "test#example.com" },{Id :3, Title : "tname-3", category: "cat2", email: "TEst#example.com" } ]
test1#example.com| [{Id :2, Title : "tname-2", category: "cat1", email: "test1#example.com" }]
but with sql I would definitely want to return only the subset of the columns, say id, title and email.

Twig creating a rowspan on loop

I have this table data:
Name | Score | Remarks
john | 80 | pass
jane | 85 | pass
How to make it look like this:
Name | Score | Remarks
john | 80 | pass
jane | 85 |
Remarks table head should create a rowspan of 2 but I'm having a prob on how to implement using twig template. Below is my code:
{% for name in names %}
<tr>
<td class="text-center">{{name.name}}</td>
<td class="text-center">{{name.score}}</td>
<td class="text-center" rowspan="2">{{name.remarks}}</td>
</tr>
{% endfor %}
The output of this code is:
Name | Score | Remarks |
john | 80 | pass |
jane | 85 | | pass
You can do like this:
{% for name in names %}
<tr>
<td class="text-center">{{name.name}}</td>
<td class="text-center">{{name.score}}</td>
{% set rowspan = new_rowspan(names, loop.index0, 'remarks') %}
{% if rowspan %}
<td class="text-center" rowspan="{{ rowspan }}">{{name.remarks}}</td>
{% endif %}
</tr>
{% endfor %}
And add a Twig extension:
class YourTwigExtension extends Twig_Extension
{
public function getFunctions()
{
return array(
new Twig_Function('new_rowspan', [$this, 'calculateRowspan']),
);
}
public function calculateRowspan($names, $from, $column)
{
// check if previous column has the same value
if ($from > 0 && $names[$from - 1][$column] === $names[$from][$column]) {
return;
}
for ($to = $from + 1; isset($names[$to]) && $names[$to][$column] === $names[$from][$column]; $to++);
return $to - $from;
}
}
Try something like this:
{% if loop.index0 % 2 == 0 %}
<td class="text-center" rowspan="2">{{name.remarks}}</td>
{% endif %}
% 2 corresponds to rowspan="2"

yii - create nested cgridview

Is it possible to create nested table using cgridview?
I'd like to have the final output as follows
| Transaction | Total |
| T-001 | $100 |
| Item | Price | // here is the nested table
| I-1 | $50 |
| I-2 | $50 |
| T-002 | $90 |
| Item | Price | // here is the nested table
| I-3 | $90 |
I know you can do this using a custom template, but i'd like a neater solution using a widget like CGRidView.
Thanks
If nested table is inside cell then you can, just create function in your model that will render table and return content. You can set third parameter of widget function to true to return content. If you want to enable pagination for nested table then be sure to manually set widget id and allow ajax update.
In model:
function getNestedTable() {
return Yii::app()->controller->widget(..., ..., true);
}
In columns definition use:
'columns' => array(
array(
'name' => 'nestedTable',
'type' => 'raw'
)
)
I think the best way to achieve what you want is to use custom functions in your CActiveRecord model (if you've a CActiveDataprovider for the grid), and put that 'nested table' as normal column:
| Transaction | Item | Price | Total |
------------------------------------------
| T-001 | I-1 | $50 | $100 |
| I-2 | $50 |
------------------------------------------
| T-002 | I-3 | $90 | $90 |
------------------------------------------
In your model you've to define get functions that return data in HTML with line breaks (for example with a br:
class Item extends CActiveRecord {
...
public function getIdItems()
{
$string = '';
foreach($this->items as $item) {
if ($string != '') $string .= '<br/>';
$string .= ' '.$item->textId; // 'I-3', 'I-2'...
}
return $string;
}
public function getPriceItems()
{
$string = '';
foreach($this->items as $item) {
if ($string != '') $string .= '<br/>';
$string .= ' '.$item->price; // $50, $90...
}
return $string;
}
...
}
And to show the new columns in your grid:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'anotacionesGrid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'transaction',
'idItems:html:Item',
'priceItems:html:Price',
'total'
)
);