add opt out for mixpanel tracking
This commit is contained in:
@@ -96,7 +96,7 @@ class UsersController < ApplicationController
|
||||
disable_categorized_saved_searches disable_tagged_filenames
|
||||
enable_recent_searches disable_cropped_thumbnails disable_mobile_gestures
|
||||
enable_safe_mode disable_responsive_mode disable_post_tooltips
|
||||
enable_recommended_posts
|
||||
enable_recommended_posts opt_out_mixpanel
|
||||
]
|
||||
|
||||
permitted_params += [dmail_filter_attributes: %i[id words]]
|
||||
|
||||
@@ -43,4 +43,4 @@ export { default as Shortcuts } from '../src/javascripts/shortcuts.js';
|
||||
export { default as Upload } from '../src/javascripts/uploads.js';
|
||||
export { default as Utility } from '../src/javascripts/utility.js';
|
||||
export { default as Ugoira } from '../src/javascripts/ugoira.js';
|
||||
|
||||
export { mixpanelInit, mixpanelEvent } from '../src/javascripts/mixpanel.js';
|
||||
|
||||
27
app/javascript/src/javascripts/mixpanel.js
Normal file
27
app/javascript/src/javascripts/mixpanel.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const mixpanelInit = (user_id, session_id, opt_out, user_data) => {
|
||||
if (typeof window.mixpanel !== "object") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user_id) {
|
||||
window.mixpanel.identify(user_id);
|
||||
|
||||
if (opt_out) {
|
||||
window.mixpanel.opt_out_tracking();
|
||||
} else {
|
||||
window.mixpanel.people.set(user_data);
|
||||
}
|
||||
} else if (session_id) {
|
||||
window.mixpanel.identify("anon:" + session_id);
|
||||
}
|
||||
}
|
||||
|
||||
const mixpanelEvent = (title, props) => {
|
||||
if (typeof window.mixpanel !== "object") {
|
||||
return;
|
||||
}
|
||||
|
||||
window.mixpanel.track(title, props);
|
||||
}
|
||||
|
||||
export { mixpanelInit, mixpanelEvent };
|
||||
@@ -60,6 +60,7 @@ class User < ApplicationRecord
|
||||
disable_responsive_mode
|
||||
disable_post_tooltips
|
||||
enable_recommended_posts
|
||||
opt_out_mixpanel
|
||||
)
|
||||
|
||||
include Danbooru::HasBitFlags
|
||||
|
||||
@@ -84,6 +84,14 @@
|
||||
$(window).trigger("danbooru:error", msg);
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
window.Danbooru.mixpanelInit(
|
||||
<%= CurrentUser.id %>,
|
||||
<%= raw session.id.to_json %>,
|
||||
<%= CurrentUser.opt_out_mixpanel? %>,
|
||||
<%= raw({"$created" =>CurrentUser.created_at.strftime('%F %T'), "$name" => CurrentUser.name, "level" => CurrentUser.level, "upload_count" => CurrentUser.post_upload_count, "post_update_count" => CurrentUser.post_update_count, "note_update_count" => CurrentUser.note_update_count, "favorite_count" => CurrentUser.favorite_count}.to_json) %>
|
||||
);
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<%= tag.body **body_attributes(CurrentUser.user) do %>
|
||||
|
||||
@@ -120,3 +120,11 @@
|
||||
<% content_for(:page_title) do %>
|
||||
Upgrade - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
|
||||
<% content_for(:html_header) do %>
|
||||
<script>
|
||||
$(function() {
|
||||
window.Danbooru.mixpanelEvent("Account Upgrade");
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
<div class="ui-corner-all ui-state-highlight" id="upgrade-account-notice">
|
||||
<h1><%= link_to "Upgrade your account for only $20!", new_user_upgrade_path %></h1>
|
||||
<h1><%= link_to "Upgrade your account for only $20!", new_user_upgrade_path, id: "goto-upgrade-account" %></h1>
|
||||
<p><%= link_to "No thanks", "#", :id => "hide-upgrade-account-notice" %></p>
|
||||
</div>
|
||||
|
||||
<%= content_for(:html_header) do %>
|
||||
<script>
|
||||
$(function() {
|
||||
$("#goto-upgrade-account").click(function() {
|
||||
window.Danbooru.mixpanelEvent("clicked upgrade notice");
|
||||
});
|
||||
$("#hide-upgrade-account-notice").click(function() {
|
||||
window.Danbooru.mixpanelEvent("hide upgrade notice");
|
||||
});
|
||||
})
|
||||
</script>
|
||||
<% end %>
|
||||
@@ -97,6 +97,8 @@
|
||||
|
||||
<%= f.input :disable_responsive_mode, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false, :hint => "Disable alternative layout for mobile and tablet" %>
|
||||
|
||||
<%= f.input :opt_out_mixpanel, :as => :select, :collection => [["No", "false"], "Yes", "true"]], :include_blank => false, :hint => "Opt out of MixPanel tracking" %>
|
||||
|
||||
<%= f.input :custom_style, :label => "Custom <a href='https://en.wikipedia.org/wiki/Cascading_Style_Sheets'>CSS</a> style".html_safe, :hint => "Style to apply to the whole site.", :input_html => {:size => "40x5"} %>
|
||||
</fieldset>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user