Skip to content

FR: Allow setting gtag.js config configurations in firebase.analytics() constructor to allow cross-domain setup #3377

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

Closed
sceee opened this issue Jul 9, 2020 · 5 comments

Comments

@sceee
Copy link

sceee commented Jul 9, 2020

Describe your environment

  • Operating System version: n/a
  • Browser version: n/a
  • Firebase SDK version: 7.15.5
  • Firebase Product: auth

Describe the problem

Currently, a cross-domain setup (website on www.example.com, WebApp on app.example.com) with Firebase JS SDK does not seem to be possible in a way that users keep one session even if moving over to the other domain.

In gtag.js, there is the option to set linker options as described here: https://developers.google.com/analytics/devguides/collection/gtagjs/cross-domain

This allows to treat separate (sub-)domains as one in terms of keeping the session for one user (including its source, campaign etc. information).

Steps to reproduce:

  • Have two or more domains: www.example.com, app.example.com
  • Use the same Firebase JS SDK config for both
  • Navigate from one page via a regular link to the other one
    => The user's session is killed when moving to the second domain. The second page (app.) has the first one (www.) as referrer even if the session started on www.* had an explicit source/medium set with custom campaign information (www.example.com?utm_source=....&...).
    This unfortunately also breaks Google Ad campaign information so it is not possible to attribute Firebase conversions made on app.* correctly back to the Google Ad that initiated the user visit.
    And there is currently no workaround as far as I know.

Proposal

My proposal is now to give the possibility to set the linker option in the firebase.analytics() constructor to be able to setup this linker behavior in gtag also when using it via firebase:

    firebase.analytics({
        'linker': {
            'domains': ['example.com', 'www.example.com', 'app.example.com']
        }
    }

When using this, it should hopefully work to track cross-domains with Firebase JS SDK.

@hsubox76
Copy link
Contributor

I did some investigating using gtag.js only, to understand linker behavior and it seems to be the case that while it does work as described for GA Web properties (ones with IDs that begin with "UA-"), it doesn't work for GA App+Web properties (ones with IDs that begin with "G-"). Unfortunately GA properties linked to Firebase projects are App+Web, so I don't think this would work even if we added the linker code to the SDK.

I suspect this is because it requires a referral exclusion list (mentioned in the "Note" on the gtag cross-domain measurement docs, which links to the referral exclusion docs) and while I did find this setting for Web properties (and it seemed to be already pre-populated with my domain name), I didn't find a similar option for App+Web properties.

I'm not sure if the GA team is planning to add this option to App+Web properties or if developers are supposed to achieve the same functionality another way, I can check with them.

@sceee
Copy link
Author

sceee commented Jul 21, 2020

@hsubox76 Hi Christina, thanks for your update. Would be great if you could check with the GA team if they know a possibility to achieve this.

@amardeepsingh20
Copy link

#3971 (comment)

@hsubox76
Copy link
Contributor

So I'm told linker functionality has now been enabled in GA4. You can already set this using gtag('config', your_measurement_id, { linker: ...}) at any time, but if you set it after initializing firebase.analytics() it will miss the initial page_view event. If that's not ideal for your use case, there is as PR in progress to allow users to set any GA config properties at the time Firebase Analytics is initialized.

#4575

This functionality will only be available on the new modularized version of the SDK, but that's already available in beta (see #4791) and will be officially released soon.

@hsubox76
Copy link
Contributor

This functionality is now available in the modularized SDK, which is in beta.

See docs: https://firebase.google.com/docs/reference/js/v9/analytics.md#initializeanalytics

Setting a linker would look something like:

const analytics = initializeAnalytics(app, { config: { linker: ... } });

@firebase firebase locked and limited conversation to collaborators Aug 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants