Skip to content
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

Fix null analytics reporter #1841

Closed
wants to merge 2 commits into from
Closed

Fix null analytics reporter #1841

wants to merge 2 commits into from

Conversation

jesuyedavid
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Oct 5, 2023

Coverage Status

coverage: 61.42% (+0.009%) from 61.411% when pulling 1c11a25 on hotfixv1.16.4 into cc55531 on master.

src/core/core.js Outdated
@@ -94,7 +95,7 @@ export default class Core {
* A local reference to the analytics reporter, used to report events for this component
* @type {AnalyticsReporter}
*/
this._analyticsReporter = config.analyticsReporter;
this._analyticsReporter = config.analyticsReporter || new AnalyticsReporter();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about falling back to the NoopAnalyticsReporter instead? If we were to create the AnalyticsReporter like this, it wouldn't be configured properly because no params are passed to the constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought NoopAnalyticsReporter does nothing when you call report(event); it simply returns true. so, if we fall back on it, and then try to report an event as we are doing on line 184, it will just report true, which is not the behavior i believe we want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought process is that if an analyticsReporter isn't present on the config, then we should use the NoopAnalyticsReporter in order to not send any analytics events. That way we won't run into an error about the analytics reporter being null. If we do want the analytics reporter to actually send the event, we should look into why the config.analyticsReporter isn't set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense! i will use NoopAnalyticsReporter then. thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have any idea why analytics reporter was missing when we do local development?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i traced it to answers-search-ui/src/answers-umd.js looks like it _analyticsReporterService was initialized as null. and then on lines 257 to 260, it didn't end up with a value probably because it didn't meet the conditions in those lines. i think it makes sense to not send any analytics in core.js if somehow, the value being passed through is null. the interface allows for that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah so I think we want to understand why it was initialized as null. It appears to work in the platform, so there is something different when you use the code editor vs when you do local development. It seems like if we can determine that then it might work. @cea2aj do you think it might be related to the api domain logic? I suspect that most developers would expect to be able to test analytics locally, which is why I would prefer to not just use the noop reporter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more likely something other than the api domain logic. Have we double checked that the businessId is set in the config? That's the only thing that affects the _eligibleForAnalytics variable in answers-umd.js. I think it's still worth using the NoopAnalyticsReporter in answers-umd if _eligibleForAnalytics is false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this. _eligibleForAnalytics is the culprit. core config needs businessId, but it looks like nationwide's global_config.json for that site didn't have businessId set. once i set it and did another run, the original issue disappeared. i will abandon this cr. thanks everyone.

@jesuyedavid jesuyedavid closed this Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants