Skip to content
Browse files

Releasing v0.2 of Google Analytics Annotations Manager.

Changelog :
-    Clean jQuery requirement ;
-    Use fireEvent with @FGRibreau jQuery library instead of
     jQuery trigger and Google Analytics Actionscript methods ;
-    Display checkboxes on panel display ;
-    Implement remove of annotations using added checkboxes ;
-    Implement basic CSV export using added checkboxes.
  • Loading branch information...
1 parent afccfa6 commit 9a732d87e0815c6ecde468becdf30bdf0a46d1be @gierschv committed Aug 27, 2011
Showing with 202 additions and 170 deletions.
  1. +0 −144 GA-AnnotationsCopy.user.js
  2. +177 −0 GA-AnnotationsManager.user.js
  3. +25 −26 README.md
View
144 GA-AnnotationsCopy.user.js
@@ -1,144 +0,0 @@
-// ==UserScript==
-// @name Google Analytics - Copy profiles annotations
-// @version 0.1
-// @license GPLv3 (see LICENSE)
-// @author Vincent Giersch <mail@vincent.sh>
-// @description Copy annotations of Google Analytics profiles
-// @include https://www.google.com/analytics/*
-// ==/UserScript==
-
-// Need an "unsafe" jQuery to trigger clicks
-(function(){
- if (typeof unsafeWindow.jQuery == 'undefined') {
- var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,
- GM_JQ = document.createElement('script');
- GM_JQ.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js';
- GM_JQ.type = 'text/javascript';
- GM_JQ.async = true;
- GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
- }
- GM_wait();
-})();
-
-function GM_wait() {
- if (typeof unsafeWindow.jQuery == 'undefined')
- window.setTimeout(GM_wait, 100);
- else
- {
- $ = unsafeWindow.jQuery.noConflict(true);
- letsJQuery();
- }
-}
-
-function letsJQuery() {
- var dumpAnnotations = function() {
- if ($('.C_ANNOTATIONS_COPY_CHCKBX').length > 0)
- {
- $('.C_ANNOTATIONS_COPY_WRAPPER').remove();
- $('.C_ANNOTATIONS_COPY_CHCKBX').remove();
- displayLinks();
- return false;
- }
-
- var dumpAnnotationsProcess = function() {
- var annotationsArray = [];
- $('.C_ANNOTATIONS_LIST > tbody:eq(1) > tr').each(function(idx, elem) {
- if ($(elem).find('input[type="checkbox"]').attr('checked') != undefined)
- {
- annotationsArray.push({
- date: $(elem).find('.C_ANNOTATIONS_DATE').text(),
- text: $(elem).find('.C_ANNOTATIONS_TEXT > span:eq(1)').text(),
- isPrivate: $(elem).find('.C_ANNOTATIONS_ACCESS_LABEL').css('display') == 'block'
- });
- }
- });
- localStorage.setItem('annotations', JSON.stringify(annotationsArray));
- $('.C_ANNOTATIONS_COPY').html(annotationsArray.length + ' annotations are into localstorage.');
- $('.C_ANNOTATIONS_CURRENT').remove();
- };
-
- $('.C_ANNOTATIONS_LIST > tbody:eq(1) > tr').append('<td class="C_ANNOTATIONS_COPY_CHCKBX"><input type="checkbox" checked /></td>');
- dumpAnnotationsProcess();
- $('.C_ANNOTATIONS_COPY_CHCKBX > input').change(dumpAnnotationsProcess);
- return false;
- };
-
- var showAnnotations = function() {
- var annotationsArray = localStorage.getItem('annotations');
- if (!annotationsArray)
- return false;
- var str = "List of annotations stored in localstorage :\n";
- annotationsArray = JSON.parse(annotationsArray);
- for (var i = 0 ; i < annotationsArray.length ; ++i)
- {
- str += annotationsArray[i].date;
- if (annotationsArray[i].isPrivate)
- str += " [private]"
- str += ": " + annotationsArray[i].text + "\n";
- }
- alert(str);
- return false;
- };
-
- var pasteAnnotationsFill = function(annotation)
- {
- var form = $('.C_ANNOTATIONS_TABLE_WRAPPER > form');
- // Fill
- $(form).find('input[name="date"]').val(annotation.date);
- $(form).find('textarea[name="text"]').val(annotation.text);
- if (annotation.isPrivate)
- $(form).find('input[name="access"]').val('PRIVATE');
- // Active form validation link
- $(form).find('textarea[name="text"]').click();
- // Send
- $('.C_ANNOTATIONS_SAVE_BUTTON > b').click();
- }
-
- var pasteAnnotations = function() {
- var annotationsArray = localStorage.getItem('annotations');
- if (!annotationsArray)
- return false;
- annotationsArray = JSON.parse(annotationsArray);
- var pasteAnnotationsCurrent = 0;
- // Active form to get AnnotationsDrawer_list form tr id
- // Trigger click trigger on "Create annotation link" not catched ? use actionscript interface instead to activate form...
- unsafeWindow.ga.component.actionscript.installedFacades_[unsafeWindow.ga.component.actionscript.installedFacades_.length - 1].addNewAnnotation();
- // Async call : waiting for token in #AnnotationsDrawer_list > table > tr id
- $(document).bind('DOMAttrModified', function(event) {
- if (event.newValue == 'C_ANNOTATIONS_CREATE_NEW C_ANNOTATIONS_BUTTON disabled')
- {
- pasteAnnotationsFill(annotationsArray[pasteAnnotationsCurrent]);
- pasteAnnotationsCurrent++;
- if (pasteAnnotationsCurrent == annotationsArray.length)
- $(document).unbind('DOMAttrModified');
- }
- else if (event.newValue == 'C_ANNOTATIONS_CREATE_NEW C_ANNOTATIONS_BUTTON' && pasteAnnotationsCurrent + 1 < annotationsArray.length)
- unsafeWindow.ga.component.actionscript.installedFacades_[unsafeWindow.ga.component.actionscript.installedFacades_.length - 1].addNewAnnotation();
- });
- };
-
- var displayLinks = function() {
- if ($('.C_ANNOTATIONS_COPY_WRAPPER').length > 0)
- return false;
- $('.C_ANNOTATIONS_CREATE_NEW').parent().append('<span class="C_ANNOTATIONS_COPY_WRAPPER">|&nbsp;\
- <a class="C_ANNOTATIONS_COPY C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">Copy annotation(s)</a></span>');
- $('.C_ANNOTATIONS_COPY').click(dumpAnnotations);
-
- var annotationsArray = localStorage.getItem('annotations');
- if (!annotationsArray || !(annotationsArray = JSON.parse(annotationsArray).length) || annotationsArray == 0)
- return false;
- $('.C_ANNOTATIONS_CREATE_NEW').parent().append('<span class="C_ANNOTATIONS_CURRENT">\
- |&nbsp;<a class="C_ANNOTATIONS_PASTE C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">Paste ' +
- annotationsArray + ' annotation(s)</a>\
- |&nbsp;<a class="C_ANNOTATIONS_SHOW C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">\
- Show annotation(s) in localstorage</a></span>');
- $('.C_ANNOTATIONS_PASTE').click(pasteAnnotations);
- $('.C_ANNOTATIONS_SHOW').click(showAnnotations);
- return true;
- }
-
- $(document).bind('DOMNodeInserted', function(event) {
- if (event.target.className.indexOf('C_ANNOTATIONS') >= 0)
- displayLinks();
- });
-}
View
177 GA-AnnotationsManager.user.js
@@ -0,0 +1,177 @@
+// ==UserScript==
+// @name Google Analytics - Manage profiles annotations
+// @version 0.2
+// @license GPLv3 : http://www.gnu.org/licenses/gpl-3.0.txt
+// @author Vincent Giersch <mail@vincent.sh>
+// @description Manage annotations of Google Analytics profiles (multiple copy, delete and CSV export). Works only on Google Analytics V5.
+// @include https://www.google.com/analytics/*
+// @require https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
+// @require https://raw.github.com/gierschv/jQuery-plugin-fireEvent/master/jquery.fireEvent.js
+// ==/UserScript==
+
+(function() {
+ var dumpAnnotations = function() {
+ var dumpAnnotationsProcess = function() {
+ var annotationsArray = [];
+ $('.C_ANNOTATIONS_LIST > tbody:eq(1) > tr').each(function(idx, elem) {
+ if ($(elem).find('input[type="checkbox"]').attr('checked') != undefined)
+ {
+ annotationsArray.push({
+ date: $(elem).find('.C_ANNOTATIONS_DATE').text(),
+ text: $(elem).find('.C_ANNOTATIONS_TEXT > span:eq(1)').text(),
+ isPrivate: $(elem).find('.C_ANNOTATIONS_ACCESS_LABEL').css('display') == 'block'
+ });
+ }
+ });
+ localStorage.setItem('annotations', JSON.stringify(annotationsArray));
+ $('.C_ANNOTATIONS_MANAGER_WRAPPER').html(' |&nbsp; ' + annotationsArray.length + ' annotations are into localstorage.')
+ .removeClass('C_ANNOTATIONS_LINKS_DISPLAYED');
+ };
+
+ dumpAnnotationsProcess();
+ return false;
+ };
+
+ var showAnnotations = function() {
+ var annotationsArray = localStorage.getItem('annotations');
+ if (!annotationsArray)
+ return false;
+ var str = "List of annotations stored in localstorage :\n";
+ annotationsArray = JSON.parse(annotationsArray);
+ for (var i = 0 ; i < annotationsArray.length ; ++i)
+ {
+ str += annotationsArray[i].date;
+ if (annotationsArray[i].isPrivate)
+ str += " [private]"
+ str += ": " + annotationsArray[i].text + "\n";
+ }
+ alert(str);
+ return false;
+ };
+
+ var exportAnnotations = function() {
+ var outputCSV = "Date,Text,Creator,Is Private\r\n", line = "";
+ $('.C_ANNOTATIONS_LIST > tbody:eq(1) > tr').each(function(idx, elem) {
+ if ($(elem).find('input[type="checkbox"]').attr('checked') != undefined)
+ {
+ line = '"' + $(elem).find('.C_ANNOTATIONS_DATE').text() + '"';
+ line += ',"' + $(elem).find('.C_ANNOTATIONS_TEXT > span:eq(1)').text().replace(/"/g, '""') + '"';
+ line += ',"' + $(elem).find('.C_ANNOTATIONS_CREATOR').text() + '"';
+ line += ',"' + ($(elem).find('.C_ANNOTATIONS_ACCESS_LABEL').css('display') == 'block' ? 'Yes' : 'No') + '"';
+ line += "\r\n";
+ outputCSV += line;
+ }
+ });
+ window.open('data:text/csv;charset=utf8,' + encodeURIComponent(outputCSV));
+ };
+
+ var pasteAnnotationsFill = function(annotation)
+ {
+ var form = $('.C_ANNOTATIONS_TABLE_WRAPPER > form');
+ $(form).find('input[name="date"]').val(annotation.date);
+ $(form).find('textarea[name="text"]').val(annotation.text);
+ if (annotation.isPrivate)
+ $(form).find('input[name="access"]').val('PRIVATE');
+ $(form).find('textarea[name="text"]').fireEvent('click', {button:1});
+ $('.C_ANNOTATIONS_SAVE_BUTTON').fireEvent('click', {button:1});
+ }
+
+ var pasteAnnotations = function() {
+ var annotationsArray = localStorage.getItem('annotations');
+ if (!annotationsArray)
+ return false;
+ annotationsArray = JSON.parse(annotationsArray);
+ var pasteAnnotationsCurrent = 0;
+ $(document).bind('DOMAttrModified', function(event) {
+ if (event.newValue == 'C_ANNOTATIONS_CREATE_NEW C_ANNOTATIONS_BUTTON disabled')
+ {
+ pasteAnnotationsFill(annotationsArray[pasteAnnotationsCurrent]);
+ pasteAnnotationsCurrent++;
+ if (pasteAnnotationsCurrent == annotationsArray.length)
+ {
+ $(document).unbind('DOMAttrModified');
+ return true;
+ }
+ $('.C_ANNOTATIONS_CREATE_NEW').fireEvent('click', {button:1});
+ return true;
+ }
+ });
+
+ $('.C_ANNOTATIONS_CREATE_NEW').fireEvent('click', {button:1});
+ };
+
+ var cancelCpyAnnotations = function() {
+ localStorage.removeItem('annotations');
+ $('.C_ANNOTATIONS_MANAGER_WRAPPER').remove();
+ displayLinks();
+ };
+
+ var removeAnnotations = function() {
+ if (!confirm('Remove these annotations ?'))
+ return false;
+ unsafeWindow.orig_confirm = unsafeWindow.confirm;
+ unsafeWindow.confirm = function() { return true; };
+ $('.C_ANNOTATIONS_LIST > tbody:eq(1) > tr').each(function(idx, elem) {
+ if ($(elem).find('input[type="checkbox"]').attr('checked') != undefined)
+ {
+ $(this).find('.C_ANNOTATIONS_EDIT_CELL > a').fireEvent('click', {button:1});
+ $('.C_ANNOTATIONS_DELETE_BUTTON:eq(1)').fireEvent('click', {button:1});
+ }
+ });
+ unsafeWindow.confirm = unsafeWindow.orig_confirm;
+ return true;
+ };
+
+ var displayLinks = function() {
+ if ($('.C_ANNOTATIONS_LINKS_DISPLAYED').length > 0)
+ return false;
+ $('.C_ANNOTATIONS_MANAGER_WRAPPER').remove();
+
+ var annotationsArray = localStorage.getItem('annotations');
+ if (annotationsArray && (annotationsArray = JSON.parse(annotationsArray).length) > 0)
+ {
+ $('.C_ANNOTATIONS_CREATE_NEW').parent().append('<span class="C_ANNOTATIONS_MANAGER_WRAPPER C_ANNOTATIONS_LINKS_DISPLAYED">\
+ |&nbsp;<a class="C_ANNOTATIONS_PASTE C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">Paste ' +
+ annotationsArray + ' annotation(s)</a>\
+ |&nbsp;<a class="C_ANNOTATIONS_SHOW C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">Show annotation(s) in localstorage</a>\
+ |&nbsp;<a class="C_ANNOTATIONS_CANCELCPY C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">Cancel copy</a>\
+ </span>');
+ $('.C_ANNOTATIONS_PASTE').click(pasteAnnotations);
+ $('.C_ANNOTATIONS_SHOW').click(showAnnotations);
+ $('.C_ANNOTATIONS_CANCELCPY').click(cancelCpyAnnotations);
+ return true;
+ }
+
+ $('.C_ANNOTATIONS_CREATE_NEW').parent().append('<span class="C_ANNOTATIONS_MANAGER_WRAPPER C_ANNOTATIONS_LINKS_DISPLAYED">\
+ | <a class="C_ANNOTATIONS_COPY C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">Copy annotation(s)</a>\
+ | <a class="C_ANNOTATIONS_REMOVE C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">Remove annotation(s)</a>\
+ | <a class="C_ANNOTATIONS_EXPORT C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">Export annotation(s) as CSV</a>\
+ |&nbsp;\
+ Select :\
+ <a class="C_ANNOTATIONS_SELECT_ALL C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">All</a>\
+ | <a class="C_ANNOTATIONS_SELECT_NONE C_ANNOTATIONS_BUTTON" onclick="return false;" href="#">None</a>\
+ </span>');
+ $('.C_ANNOTATIONS_LIST > tbody:eq(1) > tr').append('<td class="C_ANNOTATIONS_COPY_CHCKBX"><input type="checkbox" /></td>');
+
+ $('.C_ANNOTATIONS_SELECT_ALL').click(function(){ $('.C_ANNOTATIONS_COPY_CHCKBX > input[type="checkbox"]').attr('checked', true); });
+ $('.C_ANNOTATIONS_SELECT_NONE').click(function(){ $('.C_ANNOTATIONS_COPY_CHCKBX > input[type="checkbox"]').attr('checked', false); });
+
+ $('.C_ANNOTATIONS_COPY').click(dumpAnnotations);
+ $('.C_ANNOTATIONS_REMOVE').click(removeAnnotations);
+ $('.C_ANNOTATIONS_EXPORT').click(exportAnnotations);
+
+ return true;
+ };
+
+ $(document).bind('DOMNodeInserted', function(event) {
+ if (event.target.className.indexOf('C_ANNOTATIONS') >= 0)
+ {
+ if (event.target.className.indexOf('editable') >= 0)
+ {
+ $('.C_ANNOTATIONS_MANAGER_WRAPPER').remove();
+ $('.C_ANNOTATIONS_COPY_CHCKBX').remove();
+ }
+ displayLinks();
+ }
+ });
+})();
View
51 README.md
@@ -1,38 +1,37 @@
-Google Analytics Annotations Copy
-=================================
+Google Analytics Annotations Manager
+====================================
Why ?
-----
-You want to copy your annotations between Google Analytics accounts/profiles ?
-This Greasemonkey user script is for you : it provides GA annotations copy tools
-for your Google Analaytics interface.
+You want to copy your annotations between Google Analytics accounts / profiles ?
+You want to remove multiples annotations together ?
+You want to export your annotations as a CSV file ?
-How ?
------
-In first, install this userscript using Greasemonkey in Firefox (not tested yet
-in Chrom{e,ium}).
+This Greasemonkey user script is for you : it provides GA annotations manage tools for your Google Analaytics interface.
-In second, go inside the profile you want copy the annotations, (for example
-in the Visitors overview page), open the annotations panel, and click on
-"Copy annotation(s)". By default, all of the annotations from the current period
-will be copied into the localstorage. You can select or deselect copied
-annotations using the checkboxes on the right of the panel.
+How use it ?
+------------
+Install this userscript using Greasemonkey in Firefox (not tested yet
+in Chrom{e,ium}, but don't support @require support) and use the version 5 of Google Analytics.
-In third, go inside the profile you want paste the annotations, open the
-annotaions panel, and click on "Paste XX annotation(s)". You should see the
-annotations copied.
+You will show new annotations features in Google Analytics annotations panel as shown on the screenshot.
How it works ?
--------------
-This user script uses HTML5 localstorage to store the annotations into your
-browser.
+This user script uses HTML5 localstorage to store the annotations into your browser.
Screenshots
-----------
-Select which annotations you want to copy :
-
-![Select which annotations you want to copy](https://lh6.googleusercontent.com/-O7wWF_AcV78/TkVMyK8UKwI/AAAAAAAAACI/pHXJ-Tidyvg/Capture.PNG)
-
-Paste stored annotations :
-
-![Paste stored annotations](https://lh3.googleusercontent.com/-EYmepvil6EA/TkVMyIAJJXI/AAAAAAAAACM/uD-K_jNZEBY/Capture-1.PNG)
+![Sreenshot](https://lh5.googleusercontent.com/--qEEkeRfe0k/TljN9Egc1yI/AAAAAAAAAGk/a1drHp2QyvM/GA-Annotations-v0.2.PNG)
+
+Changelog
+---------
+- v0.2 :
+ - Clean jQuery requirement ;
+ - Use fireEvent with @FGRibreau jQuery library instead of
+ jQuery trigger and Google Analytics Actionscript methods ;
+ - Display checkboxes on panel display ;
+ - Implement remove of annotations using added checkboxes ;
+ - Implement basic CSV export using added checkboxes.
+- v0.1
+ - Implement copy of annotations.

0 comments on commit 9a732d8

Please sign in to comment.
Something went wrong with that request. Please try again.