-
Notifications
You must be signed in to change notification settings - Fork 529
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
feat(insights): automatically add insights middleware #5488
Changes from all commits
89cc624
934786a
c6ab548
dfd0b87
3d7aa28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import type { | |
import type { RouterProps } from '../middlewares/createRouterMiddleware'; | ||
import { createRouterMiddleware } from '../middlewares/createRouterMiddleware'; | ||
import type { InsightsEvent } from '../middlewares/createInsightsMiddleware'; | ||
import { createInsightsMiddleware } from '../middlewares/createInsightsMiddleware'; | ||
import { | ||
createMetadataMiddleware, | ||
isMetadataEnabled, | ||
|
@@ -297,12 +298,17 @@ See ${createDocumentationLink({ | |
this.sendEventToInsights = noop; | ||
|
||
if (routing) { | ||
const routerOptions = typeof routing === 'boolean' ? undefined : routing; | ||
const routerOptions = typeof routing === 'boolean' ? {} : routing; | ||
routerOptions.$$internal = true; | ||
this.use(createRouterMiddleware(routerOptions)); | ||
} | ||
|
||
// This is the default middleware, | ||
// any user-provided middleware will be added later and override this one. | ||
this.use(createInsightsMiddleware({ $$internal: true })); | ||
Comment on lines
+306
to
+308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something still needs to be fixed here, the script is always loaded from the internal middleware, even if users add a different middleware later (even right after). Not too sure how to fix that yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. solved through #5493 |
||
|
||
if (isMetadataEnabled()) { | ||
this.use(createMetadataMiddleware()); | ||
this.use(createMetadataMiddleware({ $$internal: true })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: this is technically always internal, it could be set statically in |
||
} | ||
} | ||
|
||
|
@@ -312,6 +318,8 @@ See ${createDocumentationLink({ | |
public use(...middleware: Middleware[]): this { | ||
const newMiddlewareList = middleware.map((fn) => { | ||
const newMiddleware = { | ||
$$type: '__unknown__', | ||
$$internal: false, | ||
subscribe: noop, | ||
started: noop, | ||
unsubscribe: noop, | ||
|
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 infiniteHits is added before start, it's reading from the cache before the insights middleware is started, and thus it doesn't have clickAnalytics + userToken yet
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.
to solve this, we could change some things about the insights middleware to make sure we have the search parameters right away, even before init, but that's currently not possible yet (helper is null)