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

feat: add samesite GA cookie property to enable GA in iframe #1463

Merged
merged 1 commit into from
Mar 25, 2021

Conversation

barnettx
Copy link
Contributor

Problem

Google analytics currently does not work if a form is embedded on a different site.

Solution

  • Set GA cookies to SameSite=None; Secure to allow iframe tracking
  • Browsers have recently tightened cookie rules by ensuring the top-level domain (the domain in your browser navbar) is the same as the domain of the request before sending cookies in that request. In our case, the default SameSite=Lax for GA cookies meant that GA cookies were not being sent as the top-level domain eg. https://ogp-checkfirst-test-staging.netlify.app/ differed from the requests to http://www.google-analytics.com. SameSite=None tells the browser to ignore this same-domain check and attach the cookies on the GA request.
  • As far as I can tell, setting SameSite=None has minimal security implications
  • Because SameSite=None can only be set when the cookie is also Secure and the site is secure, this means that local testing will only work if using https
  • References about SameSite cookies: https://web.dev/samesite-cookies-explained/
  • https://medium.com/trabe/cookies-and-iframes-f7cca58b3b9e

Before & After

BEFORE:
iframe-form-no-GA-har.txt

AFTER:
iframe-forms-GA-har.txt

Screenshot 2021-03-25 at 12 25 29 PM

Tests

Tested by exposing my local formsg and embedding it in a test isomer site

@liangyuanruo liangyuanruo merged commit 6a4ccf7 into develop Mar 25, 2021
@liangyuanruo liangyuanruo deleted the feat/ga-iframe branch March 25, 2021 10:15
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.

2 participants