Skip to content

Commit

Permalink
Merge pull request #2 from Aer0naut/GA-changes
Browse files Browse the repository at this point in the history
Changed from GA to CPA
  • Loading branch information
Aer0naut authored Aug 7, 2017
2 parents e4a5931 + 87c6d4a commit 1f90548
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 27 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# VSTS-GO
A Chrome extension for Visual Studio Team Services

This extension gives you an easy way to navigate directly to a workitem in Visual Studio Team Services, only by entering the id of the item.Start by creating an access token in VSTS, configure the extension - you are good to GO!
This extension gives you an easy way to navigate directly to a workitem in Visual Studio Team Services, only by entering the id of the item. Start by creating an access token in VSTS, configure the extension - you are good to GO!
Furthermore, the extension keeps a log of your latest 5 requested items, so you can easily navigatee to these.

You can install it from the [Chrome webshop](https://goo.gl/7cPqLg), for free
You can install this extension from the [Chrome webshop](https://goo.gl/7cPqLg), for free

## Release 1.5
- Changed Google Analytics to Chrome Platform Analytics
- Analytics now tracks errors
- Fixed Styling of invalid ID error message

## Release 1.4
- You can now see the latest 5 items you navigated to, and go back.
Expand Down
95 changes: 95 additions & 0 deletions google-analytics-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ border-radius: 5px;
.column-right{float:right; width: 36px; }
.error-Configure{min-width:150px; height: 100%;font-size: 10px;padding: 0px 5px 5px 5px}
.error-Request{width: 200px; height: 100%;font-size: 10px;padding: 0px 5px 5px 5px}
.error-Id{width: 130px;text-align: center;vertical-align: center;}

label{
font-weight:bold;
Expand Down
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "VSTS GO",
"short_name": "VSTS GO",
"description": "This extension will send you to a specific workitem in your VSTS, given the id",
"version": "1.4",
"version": "1.5",
"icons": {
"128": "VSTS-GO.png"
},
Expand All @@ -14,11 +14,11 @@
},
"permissions": [
"activeTab",
"https://www.google-analytics.com/",
"storage"
],
"options_ui": {
"page": "options.html",
"chrome_style": false
},
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'"
}
}
1 change: 1 addition & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>VSTS workitem</title>
<script src="jquery-3.2.1.min.js"></script>
<script src="google-analytics-bundle.js"></script>
<script src="popup.js"></script>
<link rel="stylesheet" href="main.css">
</head>
Expand Down
63 changes: 41 additions & 22 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
var accesstoken;
var domain;
var collection;
var analyticsId = 'UA-102907431-1';
var analyticsService = 'vsts-go';
var vstsApiVersion = "?api-version=3.0";
var vstsApiUrl = "_apis/wit/workItems/";
var err = new errMsg();
var recentItems = [];


//Analytics------------------------
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-102907431-1']);
_gaq.push(['_trackPageview']);

//Inserting by script to avoid security restraints in chrome extensions
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//Analytics---------------------------------------
//----------------Chrome Platform Analytics------------------------
// https://github.com/GoogleChrome/chrome-platform-analytics/wiki
var service = analytics.getService(analyticsService);
var tracker = service.getTracker(analyticsId);
tracker.sendAppView('MainView');
//----------------Chrome Platform Analytics-------------------------

//loads user configuration values and sets up click event,
//or dislplays option to configure
Expand Down Expand Up @@ -72,8 +68,6 @@ function showRecentItems(){

divRecentItems.appendChild(ulRecentItems);

console.log('length:'+ recentItems.length);

for(var i in recentItems){
var li=document.createElement('li');
li.className = 'listItem' + i;
Expand All @@ -82,8 +76,6 @@ function showRecentItems(){
li.innerHTML+= '<a href="'+
recentItems[i][1]+'" target="_blank" title="'+recentItems[i][2]+'">'+
recentItems[i][0]+': '+recentItems[i][2]+'</a>';

console.log(i + ': '+recentItems[i][0]);
}
divRecentItems.style.display='block';
}
Expand All @@ -105,6 +97,27 @@ function configIsValid(){
return true;
}


/**
* Can be used to extract the subdomain/accountname from the full url
* @param {string} strDomainUrl - a full url
* @returns {string} - subdomain/accountname
*/
function getAccountName(strDomainUrl){
/*
Form validation in options only checks for 'http://' - not '.'
So check that the string actually contains a '.'
*/
if(strDomainUrl.indexOf('.')>-1)
{
var accountName = strDomainUrl.split("//")[1].split(".")[0];
return accountName;
}
//If the url doesn't contain a '.', return the URL
return strDomainUrl;

}

function idIsValid(id){
if(id && id>1 && id<999999999){
return true;
Expand All @@ -117,6 +130,7 @@ function errMsg(){

this.invalidConfiguration = function()
{
tracker.sendAppView('InvalidConfigView');
document.body.innerHTML = '<div class="error-Configure">'+
'<h2>Please configure</h2>'+
'<button id="go-to-options">Options</button>'+
Expand All @@ -133,13 +147,15 @@ function errMsg(){
};

this.requestError = function(msg){
tracker.sendAppView('RequestErrorView');
rspText = jQuery.parseJSON(msg.responseText);
document.body.innerHTML = '<div class="error-Request"><h2>Request error</h2>'+
rspText.message;
console.log("Error: " + msg.responseText);
};

this.idInvalid = function(){
tracker.sendAppView('InvalidIdView');
document.body.innerHTML = '<div class="error-Id">'+
'<h2>ID is invalid</h2>';
}
Expand All @@ -160,7 +176,7 @@ function displayLoader(display){
}

function saveRecentItem(id,recentItemUrl,title){
//insert url,id and title in the first (0) place of the array
//insert url,id and title in the first place of the array
//then store the array

recentItems.unshift([id,recentItemUrl,title]);
Expand All @@ -186,10 +202,12 @@ function GetItem() {
if(idIsValid(id))
{

//Google Analytics--------- user requested an item, and config and id was valid
_gaq.push(['_trackEvent', 'GetItem', domain, id]);

displayLoader(true);
var account = getAccountName(domain);

//CPA - user requested an item, and config and id was valid
tracker.sendEvent('GetItem', account, id);

displayLoader(true);

//make VSTS API Call to retrieve item info
$.ajax({
Expand All @@ -202,12 +220,13 @@ function GetItem() {
success: function(data){
var goUrl = formWorkItemURL(data.fields["System.TeamProject"], id);
saveRecentItem(id,goUrl,data.fields["System.Title"]);
console.log(data.fields["System.Title"]);
tracker.sendEvent('GetItem: Succes', account, id);
window.open(goUrl , '_newtab');
displayLoader(false);
},
error: function (jqXHR, status, error) {
displayLoader(false);
tracker.sendEvent('GetItem: Error', account, id);
err.requestError(jqXHR);
}
});
Expand Down

0 comments on commit 1f90548

Please sign in to comment.