Page MenuHomePhabricator
Paste P9414

banner history logger w/o old browser race condition handling
ActivePublic

Authored by awight on Oct 21 2019, 3:15 PM.
Tags
None
Referenced Files
F30873041: raw.txt
Oct 21 2019, 3:18 PM
F30873036: raw.txt
Oct 21 2019, 3:15 PM
Subscribers
None
Not empty banner. <button class="foobutt">Foo</button>
<script lang="javascript">
/**
* Minimal banner code to report banner history information and associate with a click.
* Requires that the containing campaign have "Banner history logging" enabled.
*
* If sampling the banner history logs, use parameter `?bannerHistoryLogRate=1` for debugging.
*
* In case we need to be ultra-conservative and handle old browsers run by incredibly fast end-users, there's non-sendBeacon race condition handling in https://phabricator.wikimedia.org/P9413
*/
$( function () {
$( '.foobutt' ).click( function () {
var bannerHistoryLoggingId,
mixins = mw.centralNotice.getDataProperty( 'mixins' );
if ( mixins && mixins.bannerHistoryLogger ) {
// Note that the logging ID is not uniquely-identifying for a given user, it is `mw.user.generateRandomSessionId()` and will change between requests.
bannerHistoryLoggingId = mw.centralNotice.bannerHistoryLogger.id;
}
mw.track( 'event.WMDEBannerEvents', {
bannerAction: 'mobile-mini-banner-expanded',
// FIXME: logging ID would be passed in its own field, this was a workaround for EventLogging validation.
bannerName: 'TestBanner, logging ID ' + bannerHistoryLoggingId,
eventRate: 123
} );
} );
} );
</script>