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

Add analytics tags #167

Merged
merged 7 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ RECAPTCHA_SITE_KEY=6LdL6s--------------
RECAPTCHA_SECRET_KEY=6LdL6s--------------
DISCOURSE_ADMIN_ROLE=DISCOURSE_ADMIN_ROLE
SENTRY_DSN=http://[email protected]/project-id
GA_MEASUREMENT_ID=UA-XXXXX-Y
AMPLITUDE_API_KEY=API-KEY
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<meta name="theme-color" content="#ffffff">
</head>

<%= render 'shared/analytics_scripts'%>

<body>
<%= yield %>
</body>
Expand Down
45 changes: 45 additions & 0 deletions app/views/shared/_analytics_scripts.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '<%= ENV['GA_MEASUREMENT_ID'] %>', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->

<!-- Amplitude Analytics -->
<script type="text/javascript">
(function(e,t){var n=e.amplitude||{_q:[],_iq:{}};var r=t.createElement("script")
;r.type="text/javascript";r.async=true
;r.src="https://cdn.amplitude.com/libs/amplitude-4.5.2-min.gz.js"
;r.onload=function(){if(e.amplitude.runQueuedFunctions){
e.amplitude.runQueuedFunctions()}else{
console.log("[Amplitude] Error: could not load SDK")}}
;var i=t.getElementsByTagName("script")[0];i.parentNode.insertBefore(r,i)
;function s(e,t){e.prototype[t]=function(){
this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));return this}}
var o=function(){this._q=[];return this}
;var a=["add","append","clearAll","prepend","set","setOnce","unset"]
;for(var u=0;u<a.length;u++){s(o,a[u])}n.Identify=o;var c=function(){this._q=[]
;return this}
;var l=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"]
;for(var p=0;p<l.length;p++){s(c,l[p])}n.Revenue=c
;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut",
"setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify",
"clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","logEventWithTimestamp",
"logEventWithGroups","setSessionId","resetSessionId"]
;function v(e){function t(t){e[t]=function(){
e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}
for(var n=0;n<d.length;n++){t(d[n])}}v(n);n.getInstance=function(e){
e=(!e||e.length===0?"$default_instance":e).toLowerCase()
;if(!n._iq.hasOwnProperty(e)){n._iq[e]={_q:[]};v(n._iq[e])}return n._iq[e]}
;e.amplitude=n})(window,document);

amplitude.getInstance().init("<%= ENV['AMPLITUDE_API_KEY'] %>");
</script>
<!-- End Amplitude Analytics -->

<script>
let currentUserId = <%= @current_user ? @current_user.id : 0 %>;
amplitude.getInstance().setUserId(currentUserId !== 0 ? currentUserId : null);
</script>
6 changes: 3 additions & 3 deletions app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% content_for :head do %>
<meta property="og:title" content="Debt Collective - Fundraising" />
<meta property="og:title" content="Debt Collective - Membership" />
<meta property="og:description" content="Organizing for big change requires resources. Becoming a dues- paying member is not charity. Instead, your support is an act of ongoing solidarity with other people in debt." />
<meta property="og:type" content="text/html" />
<meta property="og:url" content="https://fundraising.debtcollective.org" />
<meta property="og:image" content="https://fundraising.debtcollective.org/assets/logo-small.png" />
<meta property="og:url" content="https://membership.debtcollective.org" />
<meta property="og:image" content="<%= asset_url('logo-small.png') %>" />
<% end %>

<header>
Expand Down