Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Remove whatsapp button on other than mobile devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuuleh committed Jun 8, 2018
1 parent dcd87c3 commit 00c7699
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions app/javascript/member-facing/track_shares.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import $ from "jquery";
import $ from 'jquery';
//TODO: Fix this import :) And rename / modify this file to hide the whatsapp button if the person is not on a mobile device
import MobileCheck from './backbone/mobile_check';

$(() => {
if (!MobileCheck.isMobile()) {
$('.button--whatsapp').remove();
}

let shared = false;

const handleShare = event => {
Expand All @@ -11,16 +17,16 @@ $(() => {
const share = event.originalEvent.share;
shared = true;

if (share.share_type === "f") {
if (share.share_type === 'f') {
ga(
"send",
"event",
"fb:sign_share",
"share_progress_share",
'send',
'event',
'fb:sign_share',
'share_progress_share',
window.champaign.personalization.urlParams.id
);
}
};

$(window).bind("share", handleShare);
$(window).bind('share', handleShare);
});
4 changes: 2 additions & 2 deletions app/liquid/shares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_all(page)
css_class: class_from_html(button.sp_button_html)
}
unless button.share_progress?
variant = random_share_variant(button.sp_type, page)
variant = select_share_variant(button.sp_type, page)
view_params[:variant_id] = variant.id
# Prepend the desired query parameters (uri encoded) into the url we want to share
url = button.url << CGI.escape("?src=whatsapp&variant_id=#{variant.id}")
Expand All @@ -32,7 +32,7 @@ def get_all_html(page)

private

def random_share_variant(share_type, page)
def select_share_variant(share_type, page)
# Whatsapp variants are served locally rather than from ShareProgress, so we need to find a way to decide
# which whatsapp share to show. The easiest way is to choose by random.
variant_class(share_type).where(page_id: page.id).order('RANDOM()').first
Expand Down

0 comments on commit 00c7699

Please sign in to comment.