Skip to content

Commit

Permalink
Merge pull request #917 from GMOD/analyticsPatch
Browse files Browse the repository at this point in the history
upgrade google analytics to analytics.js and add optional parameter to record pageviews for one or more non-JBrowse Analytics users
  • Loading branch information
rbuels authored Feb 14, 2018
2 parents e9c13c1 + 4d84ae8 commit 8882d09
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 35 deletions.
24 changes: 13 additions & 11 deletions release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Added a `--trackConfig` option to `prepare-refseqs.pl` to allow injecting
refseq configuration variables at format time. @erasche

* Added trackLabels: "no-block" config feature. Moves track labels/menus
* Added trackLabels: "no-block" config feature. Moves track labels/menus
above the features so as not to obscure the features. (issue #901, #490)

* Make jbrowse npm installable. thanks to @cmdcolin & @enuggetry.
Expand Down Expand Up @@ -56,6 +56,8 @@
* Fixed a "cannot read property 'offsetLeft'" error when using touch screens without
the old simple track selector active. (issue #893, @rbuels)

* Upgraded to use new Google Analytics API for usage reporting. (@rdhayes)

# Release 1.12.3 2017-05-02 19:20:01 America/Los_Angeles

## Minor improvements
Expand Down Expand Up @@ -105,9 +107,9 @@

* Added subfeatureDetailLevel config item to make View details box
only load subfeatures on demand (issue #861).

* Added ability to draw scatter plot from BigWig tracks. Thanks to
Keiran Raine for the contribution (issue #741).
Keiran Raine for the contribution (issue #741).

* Added a fullviewlink option for the URL bar to disable "View full
link" attribute in embedded JBrowse. Thanks to Vivek Krishnakumar
Expand Down Expand Up @@ -147,7 +149,7 @@
Eric Rasche for reporting (issue #673).

* Fixed some issues where the Gene glyph would not layout some
features correctly. Thanks to Eric Rasche for reporting
features correctly. Thanks to Eric Rasche for reporting
(issue #686).

* Fixed an issue with JBrowse Desktop where saving session would not
Expand Down Expand Up @@ -193,7 +195,7 @@

## Bug fixes

* Fix RegexSearch plugin and NeatCanvasFeatures plugin - search track
* Fix RegexSearch plugin and NeatCanvasFeatures plugin - search track
loading failure (issue #676)

* Fix compat_121.html to access /css directory
Expand Down Expand Up @@ -275,7 +277,7 @@
pointing to important data, but this is uncommon (issue #563).

* Allow falsey values to be used in browser.cookie.

* Fix minor issue where sometimes the length field of refSeqs.json
was missing.

Expand Down Expand Up @@ -421,11 +423,11 @@
chunkSizeLimit errors. Thanks to Richard Hayes for finding and
debugging this issue (issue #486)!

* Fixed a bug where the Variant popup boxes would not display
* Fixed a bug where the Variant popup boxes would not display
complete genotype information in previous 1.11.* versions.
Thanks to Nando for reporting the bug and Colin Diesh for the
bugfix (issue #488).

* Fixed a small error that occured when using variant type tracks
with the REST API.

Expand Down Expand Up @@ -466,7 +468,7 @@
menu or by using the in-memory adaptor. Big thanks to Andrew Warren
for the contribution (issue #453).

* Added a change to the highlight button to allow the user to more
* Added a change to the highlight button to allow the user to more
easily clear highlights. Thanks to Paul Hale for the suggestion
and Colin Diesh for the fix (issue #445).

Expand All @@ -480,7 +482,7 @@
original implementation and Colin Diesh for the fix (issue #461).

* Changed the CanvasFeatures 'View details' pages to display the name
and description of features in the dialog box. Thanks to Colin
and description of features in the dialog box. Thanks to Colin
Diesh for the fix (issue #463).

* Added a bugfix for non-compliant servers that add a trailing slash
Expand Down Expand Up @@ -566,7 +568,7 @@
and Colin Diesh for the bugfix (issue #435)

* Fixed a bug where gene features in GFF tracks would not have
arrowhead markers. Thanks to Colin Diesh for finding and fixing
arrowhead markers. Thanks to Colin Diesh for finding and fixing
this issue (issue #454)

# Release 1.11.2 2014-02-10 19:11:33 EST5EDT
Expand Down
81 changes: 57 additions & 24 deletions src/JBrowse/Browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var _gaq = _gaq || []; // global task queue for Google Analytics

define( [
'dojo/_base/declare',
'dojo/_base/lang',
Expand Down Expand Up @@ -141,7 +139,7 @@ constructor: function(params) {
this.globalKeyboardShortcuts = {};

this.config = params || {};

// if we're in the unit tests, stop here and don't do any more initialization
if( this.config.unitTestMode )
return;
Expand All @@ -154,7 +152,7 @@ constructor: function(params) {

// start the initialization process
var thisB = this;

dojo.addOnLoad( function() {
thisB.loadConfig().then( function() {

Expand Down Expand Up @@ -534,7 +532,7 @@ loadRefSeqs: function() {
request(this.config.refSeqs.url, {
handleAs: 'text',
headers: {
'X-Requested-With': null
'X-Requested-With': null
}
} )
.then( function(o) {
Expand Down Expand Up @@ -1674,25 +1672,60 @@ reportUsageStats: function() {

// phones home to google analytics
_reportGoogleUsageStats: function( stats ) {
_gaq.push.apply( _gaq, [
['_setAccount', 'UA-7115575-2'],
['_setDomainName', 'none'],
['_setAllowLinker', true],
['_setCustomVar', 1, 'tracks-count', stats['tracks-count'], 3 ],
['_setCustomVar', 2, 'refSeqs-count', stats['refSeqs-count'], 3 ],
['_setCustomVar', 3, 'refSeqs-avgLen', stats['refSeqs-avgLen'], 3 ],
['_setCustomVar', 4, 'jbrowse-version', stats['ver'], 3 ],
['_setCustomVar', 5, 'loadTime', stats['loadTime'], 3 ],
['_trackPageview']
]);

var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www')
+ '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
var thisB = this;
// jbrowse.org account always
var jbrowseUser = 'UA-7115575-2'
var accounts = [ jbrowseUser ];

// add any custom Google Analytics accounts from config (comma-separated or array)
if( this.config.googleAnalytics ) {
var userAccounts = this.config.googleAnalytics.accounts;
if( accounts && ! lang.isArray(userAccounts) ) {
userAccounts = userAccounts.replace(/^\s*|\s*$/,'').split(/\s*,\s*/)
}
accounts.push.apply( accounts, userAccounts );
}

var analyticsScript = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ ";
analyticsScript += "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), ";
analyticsScript += "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) ";
analyticsScript += "})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');";

// set up users
accounts.forEach(function(user,trackerNum) {
// if we're adding jbrowse.org user, also include new dimension references (replacing ga.js custom variables)
if ( user == jbrowseUser) {
analyticsScript += "ga('create', '"+user+"', 'auto', 'jbrowseTracker');";
}
else {
analyticsScript += "ga('create', '"+user+"', 'auto', 'customTracker"+trackerNum+"');";
}
});

// send pageviews and custom variables
accounts.forEach(function(user,viewerNum) {
if ( user == jbrowseUser) {
var gaData = {};
var googleDimensions = 'tracks-count refSeqs-count refSeqs-avgLen ver loadTime electron plugins';
var googleMetrics = 'loadTime';

googleDimensions.split(/\s+/).forEach( function(key,index) {
gaData['dimension'+(index+1)] = stats[key];
});

gaData.metric1 = Math.round(stats.loadTime*1000);

analyticsScript += "ga('jbrowseTracker.send', 'pageview',"+JSON.stringify(gaData)+");";
}
else {
analyticsScript += "ga('customTracker"+viewerNum+".send', 'pageview');";
}
});

var analyticsScriptNode = document.createElement('script');
analyticsScriptNode.innerHTML = analyticsScript;

document.getElementsByTagName('head')[0].appendChild(analyticsScriptNode);
},

// phones home to custom analytics at jbrowse.org
Expand Down

0 comments on commit 8882d09

Please sign in to comment.