mixpanel fixes
This commit is contained in:
@@ -50,6 +50,7 @@ class UsersController < ApplicationController
|
||||
@user.save
|
||||
if @user.errors.empty?
|
||||
session[:user_id] = @user.id
|
||||
flash[:alias_mixpanel] = true
|
||||
else
|
||||
flash[:notice] = "Sign up failed: #{@user.errors.full_messages.join("; ")}"
|
||||
end
|
||||
|
||||
@@ -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';
|
||||
export { mixpanelInit, mixpanelEvent, mixpanelAlias } from '../src/javascripts/mixpanel.js';
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
const mixpanelInit = (user_id, session_id, opt_out, user_data) => {
|
||||
const mixpanelInit = (user_id, opt_out, user_data) => {
|
||||
if (typeof window.mixpanel !== "object") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user_id) {
|
||||
window.mixpanel.identify(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);
|
||||
if (opt_out) {
|
||||
window.mixpanel.opt_out_tracking();
|
||||
} else {
|
||||
window.mixpanel.people.set(user_data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +20,12 @@ const mixpanelEvent = (title, props) => {
|
||||
window.mixpanel.track(title, props);
|
||||
}
|
||||
|
||||
export { mixpanelInit, mixpanelEvent };
|
||||
const mixpanelAlias = (user_id) => {
|
||||
if (typeof window.mixpanel !== "object") {
|
||||
return;
|
||||
}
|
||||
|
||||
window.mixpanel.alias(user_id);
|
||||
}
|
||||
|
||||
export { mixpanelInit, mixpanelEvent, mixpanelAlias };
|
||||
|
||||
@@ -84,18 +84,15 @@
|
||||
$(window).trigger("danbooru:error", msg);
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
window.Danbooru.mixpanelInit(
|
||||
<%= CurrentUser.id || "null" %>,
|
||||
<%= raw session.id.to_json %>,
|
||||
<%= CurrentUser.opt_out_mixpanel? %>,
|
||||
<% if CurrentUser.is_anonymous? %>
|
||||
{}
|
||||
<% else %>
|
||||
<% unless CurrentUser.is_anonymous? %>
|
||||
<script>
|
||||
window.Danbooru.mixpanelInit(
|
||||
"<%= CurrentUser.id %>",
|
||||
<%= 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) %>
|
||||
<% end %>
|
||||
);
|
||||
</script>
|
||||
);
|
||||
</script>
|
||||
<% end %>
|
||||
|
||||
</head>
|
||||
<%= tag.body **body_attributes(CurrentUser.user) do %>
|
||||
|
||||
@@ -20,3 +20,13 @@
|
||||
<% content_for(:page_title) do %>
|
||||
Feedback - <%= @user_feedback.user_name %> - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
|
||||
<% if flash[:alias_mixpanel] %>
|
||||
<% content_for(:html_header) do %>
|
||||
<script>
|
||||
$(function() {
|
||||
window.Danbooru.mixpanelAlias("<%= CurrentUser.id %>");
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user