-
Notifications
You must be signed in to change notification settings - Fork 38
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
refactor(ga): decouple Express.Request from analytics #279
Conversation
Move biz logic for creating GA page view requests into its own func, so that we can more easily decouple Express.Request from analytics - Declare and implement `createPageViewHit()`, call that from `sendPageViewHit()` - Augment tests to expect mockAnalyticsLogger to record and compare page view hits, to facilitate later refactoring which changes func arguments for `logRedirectAnalytics()`
Change analytics logging such that responsibility of creating view page requests to GA falls on the controller by invoking an utility function, which is then passed to `analyticsLogger` - Call `createPageViewHit` from controller, pass result to `analyticsLogger` - Change args to `logRedirectAnalytics()` such that it receives an object of generic type T, usually the type of the page view hit payload. Change GaLogger so that it implements AnalyticsLogger<IGaViewPageForm> - Rework tests to account for changes in signature
- `googleAnalytics/` => `analytics/` - AnalyticsLogger => AnalyticsLoggerService, as its own interface file - `analyticsLogger.ts` => `GaLoggerService.ts` - appropriate changes to inversify dependency ids
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.
Can we go a bit further for this refactor and
- remove the need to create a
logRedirect
function each time we have to make a redirect - remove the need to pass
req
tocreatePageViewHit
? in fact, we could refactor to makecreatePageViewHit
an internal function withinlogRedirectAnalytics
and call that at the appropriate junction, instead of exposing it toRedirectController
?
Main idea being that controllers parse req
and delegate work to services, without needing to know the internals of how other functions work.
Wouldn't that defeat the purpose of this PR? Isn't the intent to ensure that only the controller deals with the handling of Express.Request before it gets passed to the Service?
I would contend that this is what the PR is doing - it's delegating work to other modules and doesn't actually know how a |
True, but I still feel that the level of abstraction may be incomplete . If |
While true, shouldn't the need to prevent Express.Request leaking into analyticsLogger take precedence? |
Given you've made the approval I will merge this in for now. We can discuss what further changes - if any - should be made at a later point |
Problem
Closes #254
Solution
Move biz logic for creating GA page view requests into its own func,
so that we can more easily decouple Express.Request from analytics
createPageViewHit()
, call that fromsendPageViewHit()
page view hits, to facilitate later refactoring which changes
func arguments for
logRedirectAnalytics()
Change analytics logging such that responsibility of creating
view page requests to GA falls on the controller by invoking an
utility function, which is then passed to
analyticsLogger
createPageViewHit
from controller, pass result toanalyticsLogger
logRedirectAnalytics()
such that it receivesan object of generic type T, usually the type of the page view hit
payload. Change GaLogger so that it implements
AnalyticsLogger
Re-org naming
Tests
To be done in staging, exercising GA