Handling events not sent to Adobe Analytics because of internet unavailability#14259
Handling events not sent to Adobe Analytics because of internet unavailability#14259SnchitGrover wants to merge 10 commits intoadobe:masterfrom
Conversation
|
Good start @SnchitGrover. |
|
|
||
| unsentEventFileLocation.exists(function (err, exists) { | ||
| if (err) { | ||
| console.log("absdjasd"); |
There was a problem hiding this comment.
Log appropriate message. Also if an error occurs the eventParams can still be sent to for logging since internet is available.
| } else { | ||
| if(exists) { | ||
| FileUtils.readAsText(unsentEventFileLocation).done(function (content) { | ||
| FileUtils.writeText(unsentEventFileLocation, "", true).done(function () { |
There was a problem hiding this comment.
The log file should be cleared only if the data is successfully uploaded.
There was a problem hiding this comment.
If I clear the log file as soon as I successfully read it and then if there is any failure I can write those back to log file?
There was a problem hiding this comment.
you will have to implement a new shell api readAndClearFile to achieve this else there will always be a synchronisation problem.
| sendAnalyticsDataToServer(analyticsData, eventParams).done(function () { | ||
| result.resolve(); | ||
| }).fail(function (err) { | ||
| result.reject(); |
There was a problem hiding this comment.
if upload fails, log the data to the unsentEventFileLocation
| result.reject(); | ||
| }); | ||
| }).fail(function (err) { | ||
| result.reject(); |
There was a problem hiding this comment.
If file read fails try to send the current data to the server else this will also be lost.
| function sendAnalyticsDataToServer (analyticsData, eventParams) { | ||
| var result = new $.Deferred(); | ||
|
|
||
| analyticsData.push(getAnalyticsData(eventParams)); |
There was a problem hiding this comment.
get a single parameter of analyticsData for this method. Push the eventParams before invoking this method.
There was a problem hiding this comment.
I am doing this to maintain the order, if I don't do this user action to "cancel" "auto-update" would have a timestamp less than "auto-update" "render" event.
|
|
||
| function internetAvailableSendAllEvents(unsentEventFileLocation, eventParams) { | ||
| var result = new $.Deferred(); | ||
| var analyticsData = []; |
There was a problem hiding this comment.
populate the analyticsData with eventParams here itself. It will just be more consistent. This may not be desired if the ordering of events in the array makes a difference.
There was a problem hiding this comment.
We should try to maintain the event order.
| if(exists) { | ||
| FileUtils.readAsText(unsentEventFileLocation).done(function (content) { | ||
| FileUtils.writeText(unsentEventFileLocation, "", true).done(function () { | ||
| result.resolve(true); |
There was a problem hiding this comment.
what does this "true" signify ?
| } | ||
| }); | ||
| sendAnalyticsDataToServer(analyticsData, eventParams).done(function () { | ||
| result.resolve(); |
There was a problem hiding this comment.
with the current code the result promise will get resolved twice. once when the files is cleared and once here once the data is uploaded.
|
|
||
| unsentEventFileLocation.exists(function (err, fileExists) { | ||
| if (err) { | ||
| result.reject(); |
There was a problem hiding this comment.
log the error for debugging purposes.
| PreferencesManager.setViewState("nextHealthDataSendTime", currentTime + ONE_DAY); | ||
| sendHealthDataToServer().always(function() { | ||
| sendAnalyticsDataToServer() | ||
| sendAnalyticsDataToServerIfInternetAvailableElseLogtoLocalFile() |
There was a problem hiding this comment.
simply call it sendAnalyticsData or sendOrSaveAnalyticsData if you feel that information is relevant. The implementation is not open for the client so simply sendAnalyticsData should also be sufficient.
|
@SnchitGrover You will also need to sign the CLA before the changes can be merged. http://dev.brackets.io/brackets-contributor-license-agreement.html |
| } else { | ||
| if(exists) { | ||
| FileUtils.readAsText(unsentEventFileLocation).done(function (content) { | ||
| FileUtils.writeText(unsentEventFileLocation, "", true).done(function () { |
There was a problem hiding this comment.
you will have to implement a new shell api readAndClearFile to achieve this else there will always be a synchronisation problem.
| } else { | ||
| if(exists) { | ||
| FileUtils.readAsText(unsentEventFileLocation).done(function (content) { | ||
| FileUtils.writeText(unsentEventFileLocation, "", true); |
There was a problem hiding this comment.
issue of multiple reads is still not resolved.
| var unsentEventFileLocation = FileSystem.getFileForPath(brackets.app.getApplicationSupportDirectory() + "/unsentEventFile.txt"); | ||
|
|
||
| if(window.navigator.onLine){ | ||
| internetAvailableSendAllEvents(unsentEventFileLocation, eventParams).done(function() { |
There was a problem hiding this comment.
simply call it sendAllEvents
| result.resolve(); | ||
| }); | ||
| }else { | ||
| internetUnavailableSaveEventsToDisk(unsentEventFileLocation, eventParams).done(function() { |
There was a problem hiding this comment.
Simply call it saveEventToDisk.
| sendAnalyticsDataToServer(unsentEventFileLocation, analyticsData, eventParams).done(function () { | ||
| result.resolve(); | ||
| }).fail(function (err) { | ||
| console.error("Unable to send file to server"); |
There was a problem hiding this comment.
in this scenario file is not being sent. please correct the log. also, result.reject() should be added.
| unsentEventFileLocation.exists(function (err, exists) { | ||
| if (err) { | ||
| // logging the error but will still send the current eventParams which needs to be logged | ||
| console.error("Error while checking if the error log file exits or not"); |
| sendAnalyticsDataToServer(unsentEventFileLocation, analyticsData, eventParams).done(function () { | ||
| result.resolve(); | ||
| }).fail(function (err) { | ||
| console.error("Unable to send file to server"); |
There was a problem hiding this comment.
if the data is not uploaded to the server it should saved back on the disk.
| sendAnalyticsDataToServer(unsentEventFileLocation, analyticsData, eventParams).done(function () { | ||
| result.resolve(); | ||
| }).fail(function (err) { | ||
| console.error("Unable to send file to server"); |
There was a problem hiding this comment.
in this case file is not being sent to the server.
| console.error("Unable to send file to server"); | ||
| }); | ||
| }).fail(function (err) { | ||
| // If reading the file fails try to send currentEventParams to server |
There was a problem hiding this comment.
add a log here that file read failed.
| sendAnalyticsDataToServer(unsentEventFileLocation, analyticsData, eventParams).done(function () { | ||
| result.resolve(); | ||
| }).fail(function (err) { | ||
| console.error("Unable to send file to server"); |
There was a problem hiding this comment.
file is not being sent to the server here. please correct the log.
| }).fail(function (jqXHR, status, errorThrown) { | ||
| // incase request to send data to server fails write the events back to disk | ||
| analyticsData.forEach(function(event) { | ||
| internetUnavailableSaveEventsToDisk(unsentEventFileLocation, eventParams).done(function() { |
There was a problem hiding this comment.
simply call the method saveEventsToDisk
|
there are linter errors. please fix those as well. |
…handler Snchit adobe analytics local handler
|
Hi @adobe/open-source-office. I am an Adobe active employee. Please take care of the CLA check. |
|
@SnchitGrover You can see this to get rid of the CLA check #14606 (comment) |
No description provided.