-
Notifications
You must be signed in to change notification settings - Fork 113
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
Updated content security policy to allow script and style from google analytics #2649
Merged
saghoshprogress
merged 6 commits into
main
from
rajeshpaul38/csp-allow-google-analytics/INFSUS-107
Apr 6, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
921f7bf
updated content security policy to allow script and style from google…
RajeshPaul38 58bd17d
fix linter errors
RajeshPaul38 ec1e364
changed google analytics code snippet to enable tracking
RajeshPaul38 dc93744
corrected erb tag closing
RajeshPaul38 e05afdf
Removed :unsafe_inline from CSP and added nonce in CSP for allowing i…
RajeshPaul38 058fccd
allow inline script for segment
RajeshPaul38 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 11 additions & 13 deletions
24
src/supermarket/app/views/application/_analytics.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
<% if ENV['SEGMENT_WRITE_KEY'] %> | ||
<script> | ||
<%= javascript_tag nonce: content_security_policy_nonce do %> | ||
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="4.0.0"; | ||
analytics.load("<%= ENV["SEGMENT_WRITE_KEY"] %>"); | ||
analytics.page(); | ||
}}(); | ||
</script> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if ENV['GOOGLE_ANALYTICS_ID'] %> | ||
<script> | ||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
<!-- Global site tag (gtag.js) - Google Analytics --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id=<%= ENV['GOOGLE_ANALYTICS_ID'] %>"></script> | ||
<%= javascript_tag nonce: content_security_policy_nonce do %> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){window.dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
|
||
ga('create', '<%= ENV["GOOGLE_ANALYTICS_ID"] %>', 'auto'); | ||
ga('require', 'linkid', 'linkid.js'); | ||
ga('require', 'displayfeatures'); | ||
ga('send', 'pageview'); | ||
</script> | ||
<% end %> | ||
gtag('config', '<%= ENV['GOOGLE_ANALYTICS_ID'] %>'); | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This snippet doesn't seem to be working. Got the reference to the new script from this link: https://developers.google.com/analytics/devguides/collection/gtagjs