Add follow tracking for orgs with working follow (#300)

This commit is contained in:
Andy Zhao 2018-05-10 09:54:46 -04:00 committed by Ben Halpern
parent 8cbf9a216f
commit f1cd542427
5 changed files with 39 additions and 36 deletions

View file

@ -1,36 +1,42 @@
function initializeSponsorshipVisibility() {
var el = document.getElementById("sponsorship-widget") || document.getElementById("partner-content-display");
var el =
document.getElementById('sponsorship-widget') ||
document.getElementById('partner-content-display');
var user = userData();
if (el) {
setTimeout(function(){
setTimeout(function() {
if (window.ga) {
if (document.querySelectorAll('[data-partner-seen]').length === 0) {
ga('send', 'event', 'view', 'sponsor displayed on page', el.dataset.details, null);
el.dataset.partnerSeen = "true";
el.dataset.partnerSeen = 'true';
}
}
}, 400)
}, 400);
}
if (el && user && user.display_sponsors){
el.classList.add("showing");
if (el && user && user.display_sponsors) {
el.classList.add('showing');
listenForSponsorClick();
} else if (el && user) {
el.classList.remove("showing");
el.classList.remove('showing');
} else if (el) {
el.classList.add("showing");
el.classList.add('showing');
listenForSponsorClick();
}
}
function listenForSponsorClick() {
setTimeout(function(){
setTimeout(function() {
if (window.ga) {
var links = document.getElementsByClassName("partner-link");
for(var i = 0; i < links.length; i++) {
links[i].onclick = function(event){
var links = document.getElementsByClassName('partner-link');
for (var i = 0; i < links.length; i++) {
links[i].onclick = function(event) {
if (event.target.classList.contains('follow-action-button')) {
handleOptimisticButtRender(event.target);
handleFollowButtPress(event.target);
}
ga('send', 'event', 'click', 'click sponsor link', event.target.dataset.details, null);
}
};
}
}
},400)
}
}, 400);
}

View file

@ -1,18 +1,17 @@
class AdditionalContentBoxesController < ApplicationController
def index
articles_ids = params[:article_id].split(",")
@article = Article.find(articles_ids[0])
article_ids = params[:article_id].split(",")
@article = Article.find(article_ids[0])
@for_user_article = ClassicArticle.
new(current_user || @article, not_ids: articles_ids).get
new(current_user || @article, not_ids: article_ids).get
if (!user_signed_in? || current_user&.display_sponsors) &&
@article.user.permit_adjacent_sponsors &&
rand(2) == 1
@boosted_article = BoostedArticle.
new(current_user, @article, not_ids: (articles_ids + [@for_user_article])).get
end
unless @boosted_article
new(current_user, @article, not_ids: (article_ids + [@for_user_article])).get
else
@alt_classic = ClassicArticle.
new(@article, not_ids: (articles_ids + [@for_user_article])).get
new(@article, not_ids: (article_ids + [@for_user_article])).get
end
render "boxes", layout: false
end

View file

@ -44,11 +44,11 @@ class ArticleDecorator < ApplicationDecorator
end
def internal_utm_params(place="additional_box")
campaign = if boosted_additional_articles
"#{organization&.slug}_boosted"
else
"regular"
end
"?utm_source=#{place}&utm_medium=internal&utm_campaign=#{ campaign }&booster_org=#{organization&.slug}"
campaign = if boosted_additional_articles
"#{organization&.slug}_boosted"
else
"regular"
end
"?utm_source=#{place}&utm_medium=internal&utm_campaign=#{campaign}&booster_org=#{organization&.slug}"
end
end

View file

@ -158,7 +158,6 @@ class Article < ApplicationRecord
boosted_dev_digest_email Boolean, default: false
end
def self.filter_excluded_tags(tag = nil)
if tag == "hiring"
tagged_with("hiring")
@ -187,10 +186,9 @@ class Article < ApplicationRecord
stories.pluck(:path, :title, :comments_count, :created_at)
end
def self.active_eli5(time_ago)
stories = where(published:true).
tagged_with("explainlikeimfive")
stories = where(published: true).tagged_with("explainlikeimfive")
if time_ago == "latest"
stories = stories.order("published_at DESC").limit(3)

View file

@ -14,7 +14,7 @@
<% else %>
<div class="profile-pic-wrapper">
<a href="<%= followable.path + article.decorate.internal_utm_params %>"
class="<%= ' partner-link' if classification == "boosted" %>"
class="<%= "partner-link" if classification == "boosted" %>"
data-details="<%= followable&.slug if classification == "boosted" %>__PROFILE"/>
<img class="profile-image"
src="<%= ProfileImage.new(followable).get(200) %>"
@ -23,12 +23,12 @@
</div>
<div class="org-name">
<a href="<%= followable.path + article.decorate.internal_utm_params %>"
class="<%= ' partner-link' if classification == "boosted" %>"
class="<%= "partner-link" if classification == "boosted" %>"
data-details="<%= followable&.slug if classification == "boosted" %>__PROFILE" /><%= followable.name %></a>
</div>
<% end %>
<button class="cta follow-action-button user-profile-follow-button"
<button class="cta follow-action-button user-profile-follow-button <%= "partner-link" if classification == "boosted" %>"
style="color:<%= user_colors(followable)[:text] %>;background-color:<%=user_colors(followable)[:bg] %>"
data-info='{"id":<%= followable.id%>,"className":"<%= followable.class.name %>"}'
data-info='{"id":<%= followable.id %>,"className":"<%= followable.class.name %>"}'
>&nbsp;</button>
<div class="org-summary"><%= follow_cue&.html_safe || followable.summary %></div>