Send order refund to google analytics - google-analytics

I get all the information about the order and sent it to google analytics (http://www.google-analytics.com/collect) through PHP curl.
My data:
Array
(
[t] => transaction
[ti] => 5555
[tr] => 200.00
[ts] => 10.00
[tt] => 5.00
[cu] => EUR
[v] => 1
[dh] => test.com
[dl] => http://test.com/
[dr] => http://test.com/index.php?
[tid] => UA-XXXX-1
[cid] => 452396293
)
Everything works fine, I can see the orders in Google Analytics system.
How to cancel an order now? I need send refund status to GA, but how?
By google doc need add "pa=detail".
But what I still need to send there? How looks like "Hit type" (t)?
Maybe somebody can show refund example.

pa=detail is merely an example in the documentation. pa is "product action" and might be one of: detail, click, add, remove, checkout, checkout_option, purchase, refund (and obviously you want the refund).
And while I have not tested this serverside a product action with the javascript tracking code would need a hit to be sent (the docs suggest an event with a non-interaction event) so you'd have to send a pageview or event.

Ecommerce transactions that have been fully or partially refunded can be programmatically uploaded to Google Analytics by using the Management API.
There is a good Importing Refund Data using the Management API article on the developer docs.

Related

Measurement Protocol to GA4 - no Event report

I sent Even success3 to GA4 via Measurement Protocol.
Why i see this Event only in Realtime report?
I sent more than 300 event success3 every month.
I started to send this event from 10 december 2022.
I need to see this Event in usual Report. Its very important Event for me.
Screenshots:
Realtime report
Event report
(
[client_id] => 1362433930.1668150326
[non_personalized_ads] =>
[events] => Array
(
[0] => stdClass Object
(
[name] => success3
[params] => stdClass Object
(
[laen] => Väikelaen
[summa] => 500
[lang] => et
)
)
)
)
Google Analytics support said:
This could be because of issues with the event configuration via
Measurement Protocol (event shows in Realtime report but is not fully
matched). As Measurement Protocol involves custom code that we are not
able to check, we don't offer any support for it unfortunately, but I
can share you the reference page.
Also you have to bear in mind that the Custom events that you have
created will take some time to be processed in Analytics before they
show up as Existing events.
Finally, the events report has a data threshold to protect the privacy
of the users, so if you have a low user count, it will not appear in
the report.

Saving credit card information for later charge with Stripe in Woocommerce

We have a Wordpress web-shop and we are using the WooCommerce plugin and Stripe. We need to delay charging the customers until the physical items are shipped but Stripe doesn't have that functionality. We've been told to use saving-cards but we don't understand how to set this up on our backend considering that we've been using pre-built tools so far. Any idea of the integration? How does this process work?
to do this:
You create a customer and a charge but specify not to capture the charge
You then use the saved customer token to charge the customer when goods are shipped.
This isn't in php but something like this:
customer = Stripe::Customer.create({
:source => 'tok_1234',
:email => params[:stripeEmail],
})
charge = Stripe::Charge.create({
amount: #amount,
currency: 'usd',
customer: customer.id,
capture: false,
})
note: capture: false...
Then when you update the order, when goods are shipped:
charge = Stripe::Charge.create({
:amount => #amount,
:description => 'Rails Stripe customer',
:currency => 'usd',
:customer => #where you save the customer token ---,
})
welcome to StackOverflow!
While Stripe does not allow to save cards directly, you can store a tokenized anonymous version of the card and use the token to charge the card anytime.
The card's data are stored remotely by Stripe and the system is able to match the card with the token.
You can find more information here: https://stripe.com/docs/saving-cards (as you know) and here https://stripe.com/docs/charges
This topic may be also useful: Stripe Payment: Save token and customer and make payment later from token
Hope it helps.
Cheers,
Francesco

google analytics demographics intrest overview fetch

I want to get all the data from google analytics. Can you please explain how to get data of "isitors-demographics-interest-overview"
Affinity Category
In-Market Segmen
Other Category0.00% of total users
I used some codes to get data from google analatics but i am stuck on "intrest menu"
$age = Analytics::performQuery($pobj, 'data', ['metrics' => 'ga:users','dimensions' => 'ga:userAgeBracket']);
$google['age'] = $age;
/*gender*/
$gender = Analytics::performQuery($pobj, 'data', ['metrics' => 'ga:users','dimensions' => 'ga:userGender']);
$google['gender'] = $gender;
The google analytics API is not related to the Google analytics website. The google analytics website has set up reports that have been processed internally.
you can not get ALL your google analytics data unless you have a premium account in that case you can request that it be exported to BigQuery.
You can not get the interest menu report directly. Your going to have to build up the data yourself using the dimensions and metrics available

Google Analytics API data mismatch

I set up a custom variables to get data from Google Analytics and store into a local database.
Requirement : I want to get a list of the users,sessions,event label,total events,unique events,event value,operating system,browser and device category.
Problem :
I've checked the dashboard on Google Analytics, and the data is being reported fine. However, I noticed that on the Google Analytics, the data listed in the column unique events don't match the amounts I get when requesting the Google Analytics API.
Data shows by GA :
Data shows by GA API :
Query that i am using in GA API :
public function getEventsLabelByDate($params=array()) {
$defaults = array(
'metrics' => 'ga:visitors,ga:visits,ga:totalEvents,ga:uniqueEvents,ga:eventValue',
'dimensions' => 'ga:eventLabel,ga:eventCategory,ga:country,ga:operatingSystem,ga:browser,ga:date,ga:deviceCategory',
'filters' => 'ga:eventAction==Play Done',
);
$_params = array_merge($defaults, $params);
return $this->_query($_params);
}
$data = $ga->getEventsLabelByDate();
I want to know what's best to use in my API calls. Any immediate help will be highly appreciable. Thanks.
I encountered the same issue.
My workaround was to change the dimensions to ga:eventCategory and then summed up the returned uniqueEvents. That provided a number identical to the uniqueEvent per eventAction on the web interface.
Using more granular dimensions resulted in an accurate number. Hope that works for you too.

Woo Commerce - Payment Gateway (when transaction is completed)

I am trying to develop wordpress woo-commerce payment gateway.
After I complete transaction, here is my code.
`$order->update_status('on-hold',__('verifying transaction', 'woocommerce'));`
after the event is done, an json object gets displayed in the page
`{"result":"failure","messages":"","refresh":"false","reload":"false"}`
I try to set the result as 'success' but that failure result kept returning.
could anyone give me suggestion where I have to look at?
here is the whole code,
$order->update_status('on-hold',__('verifying transaction', 'woocommerce'));
return array('result' => 'success',
'redirect' => add_query_arg('order',$order->id, add_query_arg('key', $order->order_key, get_permalink(get_option('woocommerce_pay_page_id'))))
);
You may need to set page/page id for woocommerce_pay_page_id by using add_option('woocommerce_pay_page_id', $page_id) any where in your custom plugin.
Hope will sort out your issue.

Resources