MediaWiki:Centralnotice-template-Aug2015 app banner 1
<script> /* Determine if banner should be shown based on:
* A) if user hasn't seen banners too many times * * Parameters (names should be self-explanatory) * views-cookie-name * max-views * * View counter cookie expires after being untouched for 365 days * * Result is stored in mw.centralNotice.bannerData.hideResult as usual */
mw.loader.using(['mediawiki.util']).then(function() {
var viewCount = parseInt($.cookie('centralnotice_bannercount_aug2015app')) || 0; var maxViews = parseInt('1') || 10000;
var hideBanner = true; var hideReason = null;
if ( mw.util.getParamValue('force') ) { hideBanner = false; } else if ( viewCount >= maxViews ) { hideBanner = true; hideReason = 'viewLimit'; } else { hideBanner = false; viewCount += 1; $.cookie('centralnotice_bannercount_aug2015app', viewCount, { expires: 365, path: '/' }); }
// Store the results mw.centralNotice.bannerData.hideResult = hideBanner; mw.centralNotice.bannerData.hideReason = hideReason; mw.centralNotice.bannerData.viewCount = viewCount;
});
mediaWiki.centralNotice.bannerData.alterImpressionData = function( impressionData ) {
// Data for Special:RecordImpression // Returning true from this function indicates the banner was shown if (mediaWiki.centralNotice.bannerData.hideReason) { impressionData.reason = mediaWiki.centralNotice.bannerData.hideReason; } if (mediaWiki.centralNotice.bannerData.viewCount) { impressionData.banner_count = mediaWiki.centralNotice.bannerData.viewCount; } return !mediaWiki.centralNotice.bannerData.hideResult;
};
$(document).ready(function() {
/* Declare EventLogging schema for client */ mw.eventLog.declareSchema('MobileWikiAppBannerClickThrough', {revision: 13295306, schema: { "description": "Measure click/tap through rates of bannes for app installation or similar campaigns.", "properties": { "campaign_id": { "description": "The campaign. During testing this field may be not applicable. For normal production campaigns, however, this is set.", "type": "string", "required": false }, "banner_id": { "description": "The banner for the particular campaign. It's possible that there may be a banner that does not have a campaign (e.g., for testing). There will always be a banner ID.", "type": "string", "required": true } } } });
/* Attach logEvent to clickthrough */ $('a.app-banner-link').click( function() { mw.eventLog.logEvent( "MobileWikiAppBannerClickThrough", { campaign_id: "{{{campaign}}}", banner_id: "{{{banner}}}" } ); });
/* Add tracking info to link */ var d = { referrer_url : window.location.href, campaign_id : mw.centralNotice.bannerData.bannerName, install_id : Math.floor(Math.random() * 1e16).toString() }; var param = 'referrer_url=' + encodeURIComponent(d.referrer_url) + '&campaign_id=' + d.campaign_id + '&install_id=' + d.install_id; var uri = new mw.Uri( $('a.app-banner-link').prop('href') ); uri.extend({ referrer: param }); $('a.app-banner-link').prop('href', uri.toString() );
/* Show banner */ if (!mw.centralNotice.bannerData.hideResult) { $('.app-banner').show(); }
}); </script>
<style> .app-banner {
background: #555; color: #fff; display: table; width: 100%; padding: 15px 0;
} .app-banner a {
color: #fff;
} .app-banner div {
display: table-cell; vertical-align: middle;
} .app-banner-img {
padding-left: 10px; padding-right: 5px;
} .app-banner-text {
width: 100%; font-size: .8em; font-weight: bold;
} .app-banner-btn {
padding: 0 15px;
} .app-banner-btn span {
display: inline-block; background: #fff; color: #555; padding: 10px 15px; font-size: .9em; line-height: 1; font-weight: bold; border-radius: 20px; text-align: center; cursor: pointer;
} .app-banner-close {
padding: 0 15px; border-left: 1px solid #777; cursor: pointer;
} .app-banner-close img {
vertical-align: middle;
} </style>