New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Piwik.js] - Create a callback for error or success #8782
Conversation
2f46664
to
44c70f2
Compare
44c70f2
to
4ffea58
Compare
|
||
/* | ||
* Send image request to Piwik server using GET. | ||
* The infamous web bug (or beacon) is a transparent, single pixel (1x1) image | ||
*/ | ||
function getImage(request, callback) { | ||
var cb = getCallBacksRequest(callback); | ||
var image = new Image(1, 1); | ||
|
||
image.onload = function () { | ||
iterator = 0; // To avoid JSLint warning of empty block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iterator = 0
is possibly no longer needed I think, same in onerror
I'd need to do a manual test but looks good in general. For our |
Hi, It is pretty good change which i was also looking for to have a cb on Error. My doubt is have you tested with HTTP 204 with no content ? because Piwik tracker call piwik.php will always have HTTP 204 no content. I manually made the param send_image=1 to have the HTTP 200 response. because image.onError will be called even in http 204. thanks. |
cb.success(); | ||
}; | ||
|
||
image.onerror = function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this callback will be called when we have other than HTTP 200, even it is HTTP 204 no content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
204 no-content is a success, so it's ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Image object consider 204 as error. So onError executed when we have 204
instead onSuccess.
On 11-Jan-2016 3:36 pm, "dhoko" notifications@github.com wrote:
In js/piwik.js
#8782 (comment):var image = new Image(1, 1); image.onload = function () { iterator = 0; // To avoid JSLint warning of empty block
if (typeof callback === 'function') { callback(); }
cb.success();
};
image.onerror = function () {
204 no-content is a success, so it's ok.
—
Reply to this email directly or view it on GitHub
https://github.com/piwik/piwik/pull/8782/files#r49304629.
One More thing, can we add the same error cb on the trackPageview method too ? |
As the PR is quite useful is there maybe someone who wants to work on finishing this PR? That would be really helpful :) |
we'd be very interested to merge this PR for Piwik 3.0.0 - if someone wants to help we would be grateful! |
I wanted to upgrade this PR, but since the beginning I have this #9492 It's hard to work with it :/ |
Hi @dhoko or anyone else interested in this PR, Please leave a comment to get the PR re-opened if you'd like to finish it and have it merged in Piwik. Currently we don't have time to finish it ourselves but we'd love to help getting it merged when someone else will be interested 👍 |
Hi,
We cannot add a callback to detect both error and success for GET and POST.
Now, with trackEvent we can set an object as the fifth argument to set callbacks.
cf PR #7946