Google Analytics

referral exclusion list importer bookmarklet

Drag bookmarklet to your bookmarks toolbar:

GA Import domain exclusions

Instructions:

Warning! This script works best in Google Chrome. Some problems may occur in other browsers.

When the bookmarklet is already added to your toolbar, simply sign in to your Google Analytics account.

Go to Admin and select website you want to manage.

Extend Tracking info option and click Referral Exclusion List

Now press GA Import search engine bookmarklet.

In the dialog window paste a domain list separated by new line characters (keyboard enter).

Finally click Import button

That's all folks!

Source code:

( function($) {
		var token = window.preload.token.value, findIdRegex = /(?:Settings\/)([a-z0-9]+)(?:\/)/ig, id = findIdRegex.exec(window.location.hash)[1], $overlay = $('<div></div>').css({
			background : 'White',
			width : '100%',
			height : '100%',
			position : 'fixed',
			'z-index' : 999,
			top : '0px',
			opacity : '0.65'
		}).appendTo('#main'), $status = $('<div>no data</div>').css({
			'font-size' : '1.25em',
			'font-weight' : 'bolder',
			padding : '10px 0'
		}), $textarea = $('<textarea class=\'_GAYib\' placeholder=\'eg. onet.pl\'></textarea>').css({
			width : '100%',
			height : '150px'
		}), $okBtn = $('<button class=\'_GAYe _GAy\'>Import</button>').click(function() {
			var rows = csvJSON($textarea.val());

			$textarea.prop('disabled', true).val('Please wait... It may take few minutes.');
			$okBtn.prop('disabled', true);

			$status.text('initializing!');

			send(0, rows, $status);

		}), $cancelBtn = $('<div class=\'_GAde\'>Cancel</div>').click(function() {
			$dialog.remove();
			$overlay.remove();
		}), $dialog = $('<div class=\'_GAZVb\'></div>').css({
			width : '450px',
			height : '350px',
			position : 'absolute',
			top : '50%',
			left : '50%',
			'margin-top' : '-200px',
			'margin-left' : '-225px',
			'z-index' : 9999
		}).append('<div class=\'_GALwb\'>Import domains:</div>').append('<div class=\'_GAC9\'><div class=\'_GAZC\'>Domain list, new line separated</div></div>').append($('<div class=\'_GAPI\'></div>').append($textarea)).append($status).append($('<div class=\'_GAWs _GAaBb\'></div>').append($okBtn).append($cancelBtn)).appendTo('#main');

		var send = function(i, r, $c) {
			var value = r[i];

			console.log('Doing row ' + i + ' from ' + r.length + ' rows.');

			if (r.length > i) {
				$c.text((i + 1) + '/' + r.length);

				$.ajax({
				  type: 'POST',
				  url: 'https://analytics.google.com/analytics/web/submitForm?m.page=TrackingReferralExclusions&ds=' + id + '&sid=editReferralExclusion&hl=pl&authuser=0',
				  timeout: 0,
				  dataType: 'text',
				  data: {
					token : token,
					newDomain : value[0],
					editMode : 'CREATE',
					etnityVersion : 1502665082311
					},
				    success: function(msg, textStatus, jqXHR) {
						console.log('DONE FIRED!');
						if(msg === '') {
							console.log('ERROR: Empty response! Retrying!');
							setTimeout(function() { send(i, r, $c); }, 1000);
						} else {
							if(jqXHR.readyState === 4) {
								console.log('success!');
								setTimeout(function() { send(++i, r, $c); }, 1000);
						   } 
						}
					}, 
					error: function(jqXHR, err) {
						console.log('Error status: ' + err + ' RETRYING!');
					}
				});
				
			} else {
				location.reload();
			}
		};

		var csvJSON = function(csv) {

			var lines = csv.split('\n');

			var result = [];

			for (var i = 0; i < lines.length; i++) {

				if (lines[i] == '') {
					continue;
				}
				var obj = {};
				var currentline = lines[i].split(';');

				obj[0] = currentline[0];
				result.push(obj);

			}

			return result;
		};

	}(jQuery));