Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

analytics fails in safari iframe with Analytics: "Firebase Analytics is not supported in this environment" #2951

Unanswered
leon asked this question in Q&A
Discussion options

Error:

Analytics: Firebase Analytics is not supported in this environment. Wrap initialization of analytics in analytics.isSupported() to prevent initialization in unsupported environments. Details: (1) Cookies are not available. (analytics/invalid-analytics-context).

From what I have read, safari blocks third party cookies in iframes.
We will not be able to do anything about this.

my question is, what is the correct way to initialize firebase so this error goes away.

how can I call isSupported in the provide, since it's async?

I'm using firebase 9 and the new modular way.

my current config looks like this.

provideFirebaseApp(() => initializeApp(environment.firebase)),
provideAnalytics(() =>
 initializeAnalytics(getApp(), {
 config: {
 allow_ad_personalization_signals: false,
 anonymize_ip: true,
 },
 }),
),

Analytics is an object

One strange thing I also found is that if I inject the Analytics service when the initialization fails, it's not undefined but instead an empty object / class.

constructor(@Optional() private analytics: Analytics) {}
logSomething() {
 logEvent(this.analytics, ...)
}

I would think that if the initialization fails because of isSupported = false that the injected service would be undefined or null.

Maybe it has to do with how angular fire wraps the firebase Analytics in a class?
https://github.com/angular/angularfire/blob/master/src/analytics/analytics.ts#L10-L14

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /