Cancel transaction in Google analytics (add negative transaction) - google-analytics

I have a transaction with very big revenue. I'd like to delete this transaction, using this link: https://support.google.com/analytics/answer/1037443?hl=ru
But I can't understand, what data import type I should choose and And what variables should be passed.

We are going to use Google Analytics hit builder for this purpose.
Follow the steps:
Step 1: You need to have edit permission for the GA property you are trying to do this.
Step 2: Gather transaction data of that particular transaction including shipping and tax.
Step 3: Navigate to hit builder - https://ga-dev-tools.appspot.com/hit-builder
Step 4: Authorize it with your email.
Step 5: Create negative transaction in hit builder.
As you are already having a transaction, you need to apply negative values of the transaction with the same transaction ID.
v=1 // Version.
&tid=xxxxxx // Add your tracking ID here
&t=transaction // Transaction as hit type
&ti=xxxxx // Transaction ID
&tr=-xxx // Negative transaction revenue
&ts=-xx //Negative transaction Shipping
&tt=-xx //Negative transaction tax
&cu=XXX //Currency code
You can use any string as client ID.
Fill up the values by adding parameters and your hit will look something like this.
Once this is filled up, click on 'Validate Hit'
If the hit is validated, click on 'Send to Google Analytics'
Note: It will take some time for data to show up.
I have used this on a test account where I had added the transaction using hit builder, never really faced any situation where I need to do it on live. Let me know if this works.

Related

Updating Subscription status inside the database by using Stripe Webhooks

I am integrating the Stripe payment gateway with a subscription-based product website in ASP.NET Core 3.1.
I have a Subscription table in the SQL Server database. It has expiration_date (datetime) and is_active (bit) columns.
When the user subscribes to a product with a recurring price (per month), I add a current date + 1 month in the expiration_date column. I also insert 1 in is_active column to indicate that the subscription is active.
Once the first month of subscription has passed, I want the value of is_active flag of this subscription to become 0 in the database. Once the user has paid for the next month, the Current Period will update in stripe subscription and the value of is_active flag is to become 1 again.
For this purpose, I should use Stripe WebHooks. I want to get notified through webhook that a subscription period has ended. I am confused because, as per my understanding, webhook events for customer.subscription and price do not define something that gets triggered when the current period of subscription ends.
The image attached below indicates the current period and date of the next invoice. From documentation I have come to know that upcoming invoice events can be used. But I am not understanding how a webhook can be used with the upcoming invoice.
So, my questions are that which event fires at the end of the final day of one month of the subscription period and which one is fired when a new period is defined?
See https://stripe.com/docs/billing/invoices/subscription#subscription-renewal and https://stripe.com/docs/billing/subscriptions/webhooks#tracking.
When a subscription period ends, an invoice is created(invoice.created) to charge for the upcoming one. So when the cycle ends, you get a customer.subscription.updated event (because current_period_start and current_period_end are updated to the new period) and also an invoice.created event for the invoice that gets created to charge for this new period.
The way I would do it is
listen to the invoice.created event
when handling it, check that the billing_reason is subscription_cycle to differentiate from invoices created for other reasons https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
retrive the referenced subscription from the invoice(https://stripe.com/docs/api/subscriptions/retrieve) and look at the current_period_[start|end] fields, which is the information you're looking for.
You could also listen to customer.subscription.updated and check if the reason for it updating is the billing period changing(by looking for current_period_start in the previous_attributes of the Event ); or do the same as above but via invoice.paid instead of invoice.created if you only care to update your system when a successful payment is made(thats what the https://stripe.com/docs/billing/subscriptions/webhooks#tracking approach does)

Measurement Protocol with uid but without cid not received in GA

I have a booking system where a booking can be made:
1. immediately by a customer, or
2. on their behalf by a customer service agent.
For 1, I've had success POSTing an event hit to the Measurement Protocol with a cid and our uid for a "purchase". Initially without the cid, it wasn't working despite the docs saying only one of uid or cid are required.
For 2, which isn't customer initiated, when I don't pass a cid nothing comes through to GA (neither the real-time dashboard or the ecomm report).
Here's the hit for option 1, broken in to lines for easier viewing:
t=event
&v=1
&tid=UA-XXXXXXX-2
&ec=Ecommerce
&ea=Purchase
&ti=176410
&ta=Some+Affiliation
&pa=purchase
&tr=123.45
&pr1id=Repair367
&pr1nm=Something+Replacement
&pr1pr=123.45
&pr1qt=1
&pr1ca=Repair%2FInspection
&pr1ps=1
&cd3=None
&ni=1
&uid=469585
OK, so it turns out this is the case:
If using cid, your hit will appear in your property's standard view's real-time Event screen (immediately) and ecomm Sales Performance screen (~10mins later for me)
If using uid and no cid, your hit will appear ONLY in those screens under your property's UserID view.
I'd been looking in the standard view and nothing was appearing as soon as I swapped over to a uid-only hit when it was customer service initiated. So although the docs say only one of either uid or cid are required, it should mention it has a significant affect on where the data is viewable in GA.
Sigh.

How to trigger a cloud function when a date stored in a firestore doc property arrives

I'm building a multisided app where people can sell and buy food. Thats the shortest summarize possible.
When an user make a food order to a restaurant and this order has been marked as dispatched, the app generates a comission on the restaurant profile in firestore.
When the commission is created it triggers a background firebase cloud function that check if the restaurant has an active billing cycle, if not, it creates one like this:
billingCycle: {
openDate: 'the moment where the fee was created',
endDate: '4th day after' //
}
This object its created in the user profile (with correct date) and works ok!
Now I want to emit an invoice when the date of the endDate prop value arrives, here comes the question.
How can I trigger a function when the date of the endDate meet?
I was thinking in moving that decition to the app. That way the app detects when its time to trigger while is using it, but what if the user is not?
How can I trigger the firebase cloud function for emit the invoice independent the interaction of the user with the client app?
I've researched a lot to find an answer but I didn't find anything related so any kind of help is so much appreciated.
*This is the first time Im using FCF.
You can use an onUpdate trigger on documents that may get updated that way. Write code in the function that checks, on every update, if the dates match in the document. If the dates match, emit the invoice, then update the document again with a flag value that indicates the invoice is emitted.
You will also have to use that new flag to determine not to emit the invoice again on further updates (otherwise your function will send an invoice every time it's updated, when the dates match - this boolean will indicate that it already happened).

sending offline measurment data - does cid have to match the original cid?

I need to send a cart status update based on an offline activity. My customers will add items to their cart online via the website but the final checkout and purchase happen offline.
Here is my question: In the example below, a checkout step is updated. Does the client_id provided in this step have to match the original client_id used when the web user started their cart originally?
Measuring Checkout Options
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
**&cid=555 // Anonymous Client ID.**
&t=event // Event hit type
&ec=Checkout // Event Category. Required.
&ea=Option // Event Action. Required.
&pa=checkout_option // Product action (checkout_option).
&cos=2 // Checkout step.
&col=FedEx // Checkout step option.
Client ID is how Google Analytics tracks each individual user throughout their multiple sessions. So, yes- if you want that payload to be associated with the same user, then the CID will need to match- otherwise you'll be artificially inflating your user count (as well as severing the contextual data from that user).
You can parse the cookie that GA stores in the browser to obtain the CID and then fill it there. Not sure what language you're writing in, but there are plenty of snippets out there for parsing the GA cookie. You could also store the CID when it is initially generated in your own session data to be used later while offline. For example:
ga(function(tracker) {
var clientId = tracker.get('clientId');
console.log(clientId);
});
You could also provide your own CID from the start that you generate yourself and tell Google Analytics to use. This might be overkill for your situation, but I wanted to mention it as an option.

add transaction manually to Google Analytics and eCommerce

I'm using the following tutorial, http://www.lunametrics.com/blog/2014/03/04/tracking-offline-transactions-universal-analytics/ which tells us how to add a transaction manually using a url like the following:
http://www.google-analytics.com/collect?v=1&tid=UA-123456789-1&cid=75839030.509493873&t=transaction&ti=52ea5aab1f0c2&tr=1100&cd1=52ea5a8bc6a4a
This works ok. However, the eCommerce part of GA does not register a conversion, so it's not possible to use the multi channel funnels report.
I'm wondering is there a way to register a sale similar to how a shopping cart would on a webpage? Would I have to add in the "clientId" for the customer, into the cart so the sale can be recorded against all the other actions in GA?
OR am I doing something wrong? Such as not registering an item? Would this trigger the ecommerce conversion to register?
Either way, somehow the ecommerce tag is not firing, so I can't record multi channel funnels based on clientId
You need save clientId in custom dimensions and in your site (it can be hide field, for example)
If you send transaction with use real clientid (send cid and cd# parameters) = this transaction will be linked with this user and all actions with this cid
On my practice better send t=event&ec=ecommerce&ea=purchase&pa=purchse&item...
With this method I have all data in ecommerce reports

Resources