-
Notifications
You must be signed in to change notification settings - Fork 503
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
Generic web analytics tracking implementation #681
Generic web analytics tracking implementation #681
Conversation
Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io>
Codecov Report
@@ Coverage Diff @@
## master #681 +/- ##
==========================================
+ Coverage 94.23% 94.36% +0.12%
==========================================
Files 228 230 +2
Lines 5931 5959 +28
Branches 1492 1448 -44
==========================================
+ Hits 5589 5623 +34
+ Misses 304 302 -2
+ Partials 38 34 -4
Continue to review full report at Codecov.
|
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.
it would be good to ramp up some test coverage, 0.19% drop is pretty big.
@@ -0,0 +1,30 @@ | |||
// Copyright (c) 2021 Uber Technologies, Inc. |
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.
// Copyright (c) 2021 Uber Technologies, Inc. | |
// Copyright (c) 2021 The Jaeger Authors. |
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.
Is this header being added automatically?
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.
No, I believe I just copied it from some file...
@@ -0,0 +1,187 @@ | |||
// Copyright (c) 2021 Uber Technologies, Inc. |
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.
// Copyright (c) 2021 Uber Technologies, Inc. | |
// Copyright (c) 2021 The Jaeger Authors. |
} | ||
|
||
export function trackError(description: string) { | ||
if (isGaEnabled) { | ||
let msg = description; |
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.
I'm confused - all this functionality now seems to only exist in the GA implementation of IWebAnalytics, but wasn't it a general functionality that would be applicable to any other implementation? I would've expected only the reporting part to be swapped out, not all the data preparation / massaging.
|
||
// Util so "0" and "false" become false | ||
const isTruish = (value?: string | string[]) => Boolean(value) && value !== '0' && value !== 'false'; | ||
const GenericWebAnalytics: IWebAnalytics = { |
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.
maybe NoopWebAnalytics
?
@@ -85,6 +85,7 @@ export default deepFreeze( | |||
tracking: { | |||
gaID: null, | |||
trackErrors: true, | |||
customWebAnalytics: null, |
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.
is there a place where the type of this function is defined (it seems to take config as arg)?
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.
If I understand the question correct, my answer is yes it will look like
customWebAnalytics: function (config?) {
return {
init: () => { /* initialization actions */ },
trackPageView: (pathname, search) => {},
trackError: (description) => {},
trackEvent: (category, action, labelOrValue, value) => {},
context: null,
isEnabled: () => false,
}
}
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.
I meant whether we have a type definition for Config somewhere. Maybe not.
webAnalytics = config.tracking.customWebAnalytics(config) as IWebAnalytics; | ||
} else if (config.tracking && config.tracking.gaID) { | ||
webAnalytics = new GA(config); | ||
} |
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.
Another option instead of forced priority order is to allow enabling both GA and custom WA via a wrapper implementation that would dispatch events to both. But I don't feel strongly about it, the priority order seems fine.
// enable for tests, debug or if in prod with a GA ID | ||
export const isGaEnabled = isTest || isDebugMode || (isProd && Boolean(gaID)); | ||
const isErrorsEnabled = isDebugMode || (isGaEnabled && Boolean(_get(config, 'tracking.trackErrors'))); | ||
if (webAnalytics.isEnabled()) { |
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 feels like an odd ordering, checking a property before the object was initialized. I would call init()
unconditionally. It can always check isEnabled
internally if necessary, but perhaps in some cases init()
would actually initialize that property (e.g by checking if a valid app token is provided in the constructor).
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.
Alternatively, could this not be done directly in the constructor? No additional information is provided to init()
anyway.
Do you suggest making a transport layer? if so, I do not clearly understand how should it look like. Currently, I lot of logic goes with GA and data preparation to be sent. let's make alignment about the implementation itself:
Does this fit for you? Or can we reduce them to
Sure we can init them both in parallel. Wrappers could be implemented inside
Will add tests as we align about implementation if it is ok :) |
Well, depends on how you look at it. Take the logic in the init method, for example - it determines app version, checks some cookies, configures raven, etc. A good 80-90 lines of code, of which maybe 5 are related to GA. So shouldn't that same functionality be available if you're reporting events to another provider? |
5b22d04
to
605f980
Compare
Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io>
62f6f6a
to
3f71ca3
Compare
@yurishkuro, I'm not sure about transport. From my perspective transport layers remove flexibility, and add complexity. We need to expose adapters for different analytic systems or provide such ability to users. About errors. Not all systems provide specific error tracking function. So you have to track them as events. But for errors user can provide a custom logger via configuration. As for raven, we can provide it as a configuration and the user can decide to use it or not. |
ok. We can refactor that later, right now it's not worse than it was before, so I'd be ok to merge. |
🤝 Let me increase test coverage shortly! |
Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io>
@yurishkuro can you take a look at codecov analysis? https://codecov.io/gh/jaegertracing/jaeger-ui/pull/681/diff There are gaps under google analytics implementation. Those lines are related to development. Should I also cover them as well? |
the rule of thumb is to leave the code with the cumulative coverage no worse than before |
Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io>
seems the checks are stuck |
https://codecov.io/github/jaegertracing/jaeger-ui/commit/aa603193a1ed5daf343ce4d44ceda2d721ded953 Is it possible to run GA tests in both debug and non-debug mode? This will improve the coverage |
Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io>
Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io>
* Generic web analytics tracking implementation Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update due to comments, refactor Google Analytic tracker Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Add unit tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Increase test coverage Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
* Generic web analytics tracking implementation Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update due to comments, refactor Google Analytic tracker Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Add unit tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Increase test coverage Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
* Generic web analytics tracking implementation Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update due to comments, refactor Google Analytic tracker Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Add unit tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Update tests Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> * Increase test coverage Signed-off-by: Mykhailo Semenchenko <mykhailo.semenchenko@logz.io> Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
Which problem is this PR solving?
Short description of the changes
UIConfig.tracking.gaID
will be addedcustomWebAnalytics
implementation via UI configuration propertyUIConfig.tracking.customWebAnalytics
it will be used as web analytic in jaeger UI() => {}
) will be usedUIConfig.tracking.customWebAnalytics
format(also described inIWebAnalytics
in types):UIconfig.js
: