It's so simple yet i can't figure it out.
I would like to write to DB on page visit (without Google Analytics).
I would like to do it on server side.
Since there is no trigger for it, and I redirect all requests to a function, i tried :
exports.contentServer = functions.https.onRequest((request, response) => {
...
...
return response.redirect(url + "?action=" + action )
.then(function(){ // **** error : .then of undefined
//write to DB a visit
Now this will return error since response.redirect will not return a promise. (as Frank said)
I could write to DB before I redirect user, then i make the website slower.
I could do so from client side, which have security problems.
How would I capture and save every page visit ?
In a callable Cloud Function, sending a response to the client is a signal that the request is completely handled, and that Cloud Functions can shut down the contain/use it for other requests.
So there is no way to continue processing after you send the redirect back to the client. You'll either have to perform an additional request from the client, or wait with sending the redirect until you've sent the event to the database.
Note that you won't have to wait for a response from the database, which is how many analytics systems deal with this situation. They send the response, and then trust that the majority if events will make it through.
Related
I'd like to implement an ironSource Offerwall in my app. I manage user's coins with a Firestore document for each user. ironSource documentation says:
check that we haven't processed the same event before
In short, they'll continue to send callback until my server send a 200 code response to their. But how could I implement a function that check for the eventID and check if the event has already been processed? (even though this shouldn't happeb because of the 200 code response, but they suggest to do also this check).
I have integrated Smartsheet api in PHP, i am able to create the webhook and enable it. When a change is made in the sheet it hits the callback url. I am not receiving any data related to the change. I have logged the data as $_POST which is empty.
function smartWebhook_post(){
log_message('error','SS data: '.print_r($_POST,true), '', 'smartsf');
$this->response(array('HTTP status'=>200));
}
According to the documentation HTTP status 200 has to be sent back.
Every webhook callback will have a JSON body. So I'd look more closely at how you are handing the POST payload.
Note that the very first callback will be a verification request as per http://smartsheet-platform.github.io/api-docs/?javascript#webhook-verification
I use a payment gateway which uses the relay response url of my web application to return the transaction response or receipt information. The problem is that it uses a timeout i.e if it is 10 seconds since it made the request to the relay response url and if the relay response url didn't respond within that time then it will timeout. The problem i am trying to avoid or minimize is for the url to respond within the timeout period. One thing i have noticed is that this method that relay response url points to over the time has gotten bulkier and this may amount to the occasional timeouts that is happening. One solution i think could be to render partial response quickly like "Please wait...". If the payment gateway receives something from the relay response url then it shouldn't timeout. After that when the heavy processing is complete then the relay method sending full response which will be receipt in most cases. Is there a way to achieve this? I appreciate any help! The framework i am using for my application is grails 2.0.
I thought something like this would work but i was wrong.
def receiptFinal(){
...
}
def receipt(){
render "Please wait..."
redirect(controller: 'payment', action: 'receiptFinal')
}
Yes,it is quite possible I guess. Your payment gateway has to make two requests. One is to confirm whether validation/payment is all right or not. And, Second request to the client would be final response (like receipt etc)
It would totally depend on payment gateway.
--
Jitendra
I have a method called GetAuthCode(). It is used to get an authorization code from an API server for my web server. I then store this code in the cache.
Because there is an expire time of this authorization code. So when it is expired, I'll call GetAuthCode() again.
Question:
If there comes 10 request 'simultaneously'(considering network deny) and the code has been expired, each request will call GetAuthCode().
Under this circumstance, I only want the very first request to successfully call GetAuthCode(). So I want to 'lock' this method:
When GetAuthCode() has been called, it can't be called by others at that moment
I have an ashx to do some sync work; it usually takes about 8 minutes. When the sync finishes, an email will be sent to admin. But when I run that ashx in browser, it keeps on loading forever after it finishes, so that admin gets more than one email.
Can anyone give me some information about why this happens?
If the handler is not returning data to the response, maybe the browser is trying to request again until get a successful status. In this case, you may try to response any text just for retrieve success:
context.Response.StatusCode = 200;
context.Response.ContentType = "text/plain";
context.Response.Write(string.Empty);
But, if the handler is returning data to the response and the response status code is successful, you may try to stop the response just after send the e-mail:
context.Response.End();
return;
And, just for check, verify if you are iterating over a loop that calls the mail sending more than one time.