Skip to content

Commit

Permalink
Add analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
shahidhk committed Jul 25, 2016
1 parent 6915b14 commit 0301ef7
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 20 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Cross platform desktop application for authenticating Windows/Linux/Mac devices

#### Note: app works only inside IIT Madras campus network.

![image](preview.png)
![image](https://github.com/shahidhk/iitm-network-auth-app/raw/master/preview.png)

## Installation

Expand All @@ -19,7 +19,8 @@ Download the latest release for your platform from [GitHub Releases page](https:
- Keep the application open to maintain the login session.
- Use the logout button to terminate the session.
- Note: each login session is valid for 10 minutes. The application refresh the session every 9 minutes. Hence, even if you close the application, the session maybe valid for at-most 10 minutes, unless you logout.
- The app will automatically download and install updates.
- The app will automatically download and install updates on Windows and Mac.
- New updates will be shown at the bottom, click that to download.

## Privacy and Security

Expand Down
40 changes: 34 additions & 6 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<script type="text/javascript" src="./node_modules/angular-aria/angular-aria.js"></script>
<script type="text/javascript" src="./node_modules/angular-animate/angular-animate.js"></script>
<script type="text/javascript" src="./node_modules/angular-material/angular-material.js"></script>
<script type="text/javascript" src="./node_modules/angulartics-google-analytics/dist/angulartics-ga.min.js"></script>
<script type="text/javascript" src="./node_modules/angulartics/dist/angulartics.min.js"></script>
<script type="text/javascript" src="./node_modules/angulartics-google-analytics/dist/angulartics-ga.min.js"></script>

<script type="text/javascript" src="scripts/index.js"></script>
<script type="text/javascript" src="scripts/vendor/external_links.js"></script>
Expand All @@ -27,7 +30,7 @@
<md-progress-linear md-theme="docs-dark" md-mode="{{auth.loading ? 'indeterminate' : null}}"></md-progress-linear>
<div layout="row" layout-align="center center">
<div>
<img ng-src="res/iitm.png" class="logo" flex >
<img ng-src="res/iitm.png" class="logo" flex draggable=false>
</div>
</div>

Expand Down Expand Up @@ -58,19 +61,44 @@
</div>

<section layout="row" layout-sm="column" layout-align="center center" layout-wrap>
<md-button class="md-primary md-raised" type="submit" aria-label="Add task">Login</md-button>
<md-button ng-click="auth.logout()" class="md-raised md-warn">Logout</md-button>
<md-button ng-click="auth.forget()" class="md-raised ">Forget me</md-button>
<md-button class="md-primary md-raised" type="submit" aria-label="Login">Login</md-button>
<md-button ng-click="auth.logout()" class="md-raised md-warn" >Logout</md-button>
<md-button ng-click="auth.forget()" class="md-raised" >Forget me</md-button>
</section>

<section layout="row" layout-sm="column" layout-align="center center" layout-wrap>
<md-button ng-href="https://shahidhk.github.io/iitm-network-auth-app" class="js-external-link">About</md-button>
<md-button>Test Update</md-button>
<md-button ng-href="https://shahidhk.github.io/iitm-network-auth-app" class="js-external-link">About v{{auth.appDetails.version}}</md-button>
<md-button ng-href="{{auth.updateData.url}}" class="js-external-link md-primary" ng-show="auth.updateAvailable">Update to v{{auth.updateData.name}}</md-button>
</section>
</form>

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

var GA_LOCAL_STORAGE_KEY = 'ga:clientId';

ga('create', _id, 'auto', {
'storage': 'none',
'clientId': localStorage.getItem(GA_LOCAL_STORAGE_KEY)
});

ga(function(tracker) {
localStorage.setItem(GA_LOCAL_STORAGE_KEY, tracker.get('clientId'));
// override parameters to remove reference to user-specific data
tracker.set('&dl', 'http://iitm-network-auth-app');
tracker.set('&dp', '/app');
tracker.set('dp', '/app');
tracker.set('page', '/app');
});

ga('set', 'checkProtocolTask', null);

</script>
</body>
</html>
15 changes: 11 additions & 4 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var feedURL = "";
// Don't use auto-updater if we are in development
if (!isDevelopment) {
if (os.platform() === 'darwin') {
updateFeed = 'https://server.waviness63.hasura-app.io/update/darwin/' + app.getVersion();;
updateFeed = 'https://server.waviness63.hasura-app.io/update/darwin/' + app.getVersion();
}
else if (os.platform() === 'win32') {
updateFeed = 'https://server.waviness63.hasura-app.io/update/win32/' +app.getVersion();
Expand Down Expand Up @@ -76,7 +76,7 @@ app.on('ready', function() {
// Other options available at:
// http://electron.atom.io/docs/latest/api/browser-window/#new-browserwindow-options
var w = 400;
var h = 600;
var h = 650;
mainWindow = new BrowserWindow({
name: "iitm-network-auth",
width: w,
Expand All @@ -93,8 +93,9 @@ app.on('ready', function() {
// Target HTML file which will be opened in window
mainWindow.loadURL('file://' + __dirname + "/index.html");

// Uncomment to use Chrome developer tools
//mainWindow.webContents.openDevTools({detach:true});
if (isDevelopment) {
mainWindow.webContents.openDevTools({detach:true});
}

// Cleanup when window is closed
mainWindow.on('closed', function() {
Expand Down Expand Up @@ -149,3 +150,9 @@ ipcMain.on('do-log-in', function (event, username, password) {
auth.login()
});

ipcMain.on('get-app-details', function() {
var details = {};
details.version = app.getVersion();
details.platform = os.platform();
mainWindow.webContents.send('app-details', details);
});
4 changes: 3 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "iitmnetworkauthapp",
"productName": "IIT Madras Network Auth",
"version": "0.2.1",
"version": "0.2.2",
"description": "Cross platform application for authentication inside IIT Madras campus network.",
"repository": "https://github.com/shahidhk/iitm-network-auth-app",
"author": "Shahidh K Muhammed <[email protected]>",
Expand All @@ -12,6 +12,8 @@
"angular-animate": "^1.5.5",
"angular-aria": "^1.5.5",
"angular-material": "^1.0.8",
"angulartics": "^1.1.2",
"angulartics-google-analytics": "^0.2.0",
"electron-squirrel-startup": "^1.0.0",
"iitm-network-auth": "^0.3.0",
"winston": "^2.2.0"
Expand Down
44 changes: 39 additions & 5 deletions app/scripts/app/authController.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
(function(){

angular
.module('app', ['ngMaterial', 'ngAnimate'])
.controller('AuthController', ['$scope', '$window', '$mdToast', 'logger', 'ipcRenderer', AuthController]);

function AuthController($scope, $window, $mdToast, logger, ipcRenderer) {
.module('app', ['ngMaterial', 'ngAnimate', 'angulartics', 'angulartics.google.analytics'])
.controller('AuthController', ['$scope', '$window', '$mdToast', 'logger', 'ipcRenderer', '$analytics', '$http', AuthController]);

function AuthController($scope, $window, $mdToast, logger, ipcRenderer, $analytics, $http) {
// List of bindable properties and methods
var ctrl = this;
// Get username and password from localstorage
Expand All @@ -21,19 +20,35 @@
ctrl.forget = forget;
ctrl.shouldConnect = true;
ctrl.updateRemember = updateRemember;
ctrl.pageOpened = false;
ctrl.updateData = {};
ctrl.updateAvailable = false;
ctrl.appDetails = {};

ipcRenderer.on('log-in-done', function (e, arg) {
if (!ctrl.pageOpened) {
$analytics.pageTrack('/app');
ctrl.pageOpened = true;
}
$analytics.eventTrack('login', {page: '/app'});
ctrl.loading = false;
ctrl.connected = true;
showToast('Logged in with id: ' + arg.data.message);
ipcRenderer.send('get-app-details');
$scope.$apply();
});
ipcRenderer.on('error-happened', function (e, a) {
$analytics.eventTrack('error', {page: '/app', error: a});
ctrl.loading = false;
showToast('ERROR: ' + a.data.error);
var reason = a.data.error.name || a.data.error;
if (reason == "RequestError") {
reason = "Not connected";
}
showToast('ERROR: ' + reason);
$scope.$apply();
});
ipcRenderer.on('log-out-done', function (event, arg) {
$analytics.eventTrack('logout', {page: '/app'});
ctrl.loading = false;
ctrl.connected = false;
showToast('Logged out');
Expand All @@ -43,6 +58,7 @@
}
});
ipcRenderer.on('session-refreshed', function (e) {
$analytics.eventTrack('refresh', {page: '/app'});
showToast('Session refreshed');
});
ipcRenderer.on('update-message', function(event, method) {
Expand All @@ -66,6 +82,7 @@
}

function forget() {
$analytics.eventTrack('forget', {page: '/app'});
logout();
ctrl.username = '';
ctrl.password = '';
Expand All @@ -89,12 +106,29 @@
);
}


// Logout and start a new session when app opens
if (ctrl.credentials) {
ipcRenderer.send('do-log-out');
} else {
showToast("Enter credentials");
}

ipcRenderer.on('app-details', function(event, args){
ctrl.appDetails = args;
$http.get('https://server.waviness63.hasura-app.io/update/'+ args.platform + '/' + args.version).then(
function(resp) {
if (resp.data) {
ctrl.updateAvailable = true;
ctrl.updateData = resp.data;
showToast('Update available');
}
},
function(error) {
showToast('ERROR: Unable to reach update server');
}
);
});
}

})();
9 changes: 7 additions & 2 deletions app/scripts/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

angular
.module('app')
.config(['$mdThemingProvider', configure]);
.config(['$mdThemingProvider', configure])
.config(['$analyticsProvider', analyticsConfigure]);

function analyticsConfigure($analyticsProvider) {
$analyticsProvider.virtualPageviews(false);
}

function configure($mdThemingProvider) {
// Configure a dark theme with primary foreground yellow
Expand All @@ -13,4 +18,4 @@
.foregroundPalette['3'] = 'yellow';
}

})();
})();
Binary file modified preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0301ef7

Please sign in to comment.