-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add onetrust and gtm changes with feature flags
Signed-off-by: ayush-billore <[email protected]>
- Loading branch information
1 parent
7ada2c5
commit bacd905
Showing
3 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
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
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,20 +1,91 @@ | ||
<% if ENV['SEGMENT_WRITE_KEY'] %> | ||
<% if gtm_enabled? %> | ||
<!-- Google Tag Manager conditional --> | ||
<%= 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(); | ||
}}(); | ||
var oneTrustHelper = (function () { | ||
function evalGTMScript() { | ||
var gtmScript = document.getElementById("GTMScript"); | ||
gtmScript.type = "text/javascript"; | ||
gtmScript.classList.remove("optanon-category-1"); | ||
eval(gtmScript.innerHTML); | ||
}; | ||
|
||
return { | ||
gtmFallback: function () { | ||
console.warn('OneTrust not loaded.'); | ||
if (document.readyState !== 'loading') { | ||
evalGTMScript(); | ||
} else { | ||
document.addEventListener('readystatechange', function () { | ||
if (document.readyState === 'interactive') { | ||
evalGTMScript(); | ||
} | ||
}); | ||
}; | ||
} | ||
}; | ||
})(); | ||
<% end %> | ||
<% end %> | ||
|
||
<% if onetrust_enabled? %> | ||
<script async src="https://cdn.cookielaw.org/consent/e231efa5-3ed9-4b92-96bc-f4c0872ca486/otSDKStub.js" type="text/javascript" charset="UTF-8" data-domain-script="e231efa5-3ed9-4b92-96bc-f4c0872ca486" onerror="oneTrustHelper.gtmFallback()"></script> | ||
<% end %> | ||
|
||
<% if gtm_enabled? && ENV['GTM_ID'] %> | ||
<!-- Google Tag Manager --> | ||
<%= javascript_tag type: "text/plain", id: "GTMScript", class: "optanon-category-1" do %> | ||
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | ||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | ||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= | ||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); | ||
})(window,document,'script','dataLayer','<%= ENV['GTM_ID'] %>'); | ||
<% end %> | ||
<% end %> | ||
|
||
<% if gtag_enabled? %> | ||
<!-- GTag conditional --> | ||
<%= javascript_tag nonce: content_security_policy_nonce do %> | ||
var oneTrustHelper = (function () { | ||
function evalGTagScript() { | ||
var gtScript = document.getElementById("GTagScript"); | ||
gtScript.type = "text/javascript"; | ||
gtScript.classList.remove("optanon-category-2"); | ||
eval(gtScript.innerHTML); | ||
}; | ||
return { | ||
gtagFallback: function () { | ||
console.warn('OneTrust not loaded.'); | ||
if (document.readyState !== 'loading') { | ||
evalGTagScript(); | ||
} else { | ||
document.addEventListener('readystatechange', function () { | ||
if (document.readyState === 'interactive') { | ||
evalGTagScript(); | ||
} | ||
}); | ||
}; | ||
} | ||
}; | ||
})(); | ||
<% end %> | ||
<% end %> | ||
|
||
<% if ENV['GOOGLE_ANALYTICS_ID'] %> | ||
<% if gtag_enabled? && ENV['GOOGLE_ANALYTICS_ID'] %> | ||
<!-- 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()); | ||
|
||
gtag('config', '<%= ENV['GOOGLE_ANALYTICS_ID'] %>'); | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% if ENV['SEGMENT_WRITE_KEY'] %> | ||
<%= 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(); | ||
}}(); | ||
<% 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