diff --git a/UrlEditorPRO/app/manifest.json b/UrlEditorPRO/app/manifest.json index 55892e5..ea02740 100644 --- a/UrlEditorPRO/app/manifest.json +++ b/UrlEditorPRO/app/manifest.json @@ -3,7 +3,7 @@ "name": "Url Editor PRO", "description": "Url parser which makes editing complex URLs as easy as possible. Features: params decoding, auto-suggest, keyboard navigation..", - "version": "0.8.3.0", + "version": "0.8.3.1", "permissions": [ "http://*/*", @@ -28,5 +28,5 @@ } } }, - "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'" + "content_security_policy": "script-src 'self' https://www.google-analytics.com; object-src 'self'" } \ No newline at end of file diff --git a/UrlEditorPRO/app/modules/autosuggest.ts b/UrlEditorPRO/app/modules/autosuggest.ts index 05b5d9a..76a7308 100644 --- a/UrlEditorPRO/app/modules/autosuggest.ts +++ b/UrlEditorPRO/app/modules/autosuggest.ts @@ -281,8 +281,18 @@ switch (elem.className) { case "suggestion": this.inputElem.value = (elem).suggestionText; + + Tracking.trackEvent(Tracking.Category.AutoSuggest, "used"); + + // trigger event which will update param in the url (via view model) + var e = new Event("updated"); + e.initEvent("updated", true, true); + this.inputElem.dispatchEvent(e) break; case "delete": + + Tracking.trackEvent(Tracking.Category.AutoSuggest, "delete"); + this.deleteSuggestion(elem.parentElement); // prevent from triggering same event on suggestion evt.stopPropagation(); @@ -328,7 +338,8 @@ } Tracking.trackEvent(Tracking.Category.AutoSuggest, "used"); - + + // trigger event which will update param in the url (via view model) var e = new Event("updated"); e.initEvent("updated", true, true); this.inputElem.dispatchEvent(e) diff --git a/UrlEditorPRO/app/modules/helpers.ts b/UrlEditorPRO/app/modules/helpers.ts index 8ca3c56..7c7ae33 100644 --- a/UrlEditorPRO/app/modules/helpers.ts +++ b/UrlEditorPRO/app/modules/helpers.ts @@ -47,8 +47,8 @@ module UrlEditor { /** * Wrapper for document.getElementById */ - export function ge(elementId: string): HTMLElement { - return document.getElementById(elementId); + export function ge(elementId: string): T { + return document.getElementById(elementId); } /** diff --git a/UrlEditorPRO/app/modules/tracking.ts b/UrlEditorPRO/app/modules/tracking.ts index a7601b1..fb16d17 100644 --- a/UrlEditorPRO/app/modules/tracking.ts +++ b/UrlEditorPRO/app/modules/tracking.ts @@ -13,37 +13,46 @@ module UrlEditor.Tracking { Sort } - _gaq = window["_gaq"] = window["_gaq"] || []; - _gaq.push(['_setAccount', 'UA-81916828-1']); + export class Dimension { + public static Version = "dimension1"; + } var enableLogOncePerSession = true; var trackingEnabled = true; var logOncePerSession: IMap = {}; + // create global analytics object + (function internalInit(hostObject, propertyName) { + hostObject['GoogleAnalyticsObject'] = propertyName; + hostObject[propertyName] = hostObject[propertyName] || function () { + (hostObject[propertyName].q = hostObject[propertyName].q || []).push(arguments) + }; + hostObject[propertyName].l = 1 * new Date(); + })(window, 'ga'); + + // initial tracking variavles setup + ga('create', 'UA-81916828-1', 'auto'); + ga('set', 'checkProtocolTask', null); // Disables file protocol checking. + export function init(_trackingEnabled: boolean) { trackingEnabled = _trackingEnabled; if (!trackingEnabled) { return; } - - _gaq.push(['_trackPageview']); - - 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); + + // load Analytics library + var a = document.createElement("script"); + a.async = true; + a.src = "https://www.google-analytics.com/analytics.js"; + var m = document.getElementsByTagName("script")[0]; + m.parentNode.insertBefore(a, m); + + ga('send', 'pageview'); } - export function trackUserVariable(name: string, value: string) { - _gaq.push(['_setCustomVar', - 1, // This custom var is set to slot #1. Required parameter. - name, // The name of the custom variable. Required parameter. - value, // The value of the custom variable. Required parameter. - 1 // Sets the scope to visitor-level. Optional parameter. - ]); + export function setCustomDimension(name: string, value: string) { + ga('set', name, value); } export function trackEvent(category: Category, action: string, label?: string, value?: string | number) { @@ -51,17 +60,12 @@ module UrlEditor.Tracking { return; } - var eventData: Array = ["_trackEvent", Category[category], action]; - - addOptionalEventParam(eventData, label); - addOptionalEventParam(eventData, value); - // check if we should log this event - if (!isLoggingEnabled(eventData)) { + if (!isLoggingEnabled(Array.prototype.slice.call(arguments))) { return; } - - _gaq.push(eventData); + + ga('send', 'event', Category[category], action, label, value); } function addOptionalEventParam(eventData: Array, param: string | number) { diff --git a/UrlEditorPRO/app/modules/view_model.ts b/UrlEditorPRO/app/modules/view_model.ts index 6686fd8..c8675f9 100644 --- a/UrlEditorPRO/app/modules/view_model.ts +++ b/UrlEditorPRO/app/modules/view_model.ts @@ -32,7 +32,7 @@ constructor(private url: Uri, private doc: HTMLDocument, settings: Settings, private submit: (uri: Uri, openIn: OpenIn) => void) { - this.measureElem = ge("measure"); + this.measureElem = ge("measure"); // bind event handlers doc.body.addEventListener("click", evt => this.clickEventDispatcher(evt)); @@ -135,7 +135,7 @@ } if (activeElem.id != "full_url" || !isTextFieldActive) { - (ge("full_url")).value = this.url.url(); + ge("full_url").value = this.url.url(); } } @@ -165,7 +165,7 @@ private populateParams(setFocusOnLastOne: boolean = false) { var param: IParamContainerElement; - var params = ge("params"); + var params = ge("params"); // clean old set of params params.innerHTML = ""; @@ -217,8 +217,13 @@ this.doc.body.style.width = Math.min(longestBoth, maxClientWidth) + "px"; } - if (setFocusOnLastOne && param) { - param.nameElement.focus(); + if (setFocusOnLastOne) { + if (param) { + param.nameElement.focus(); + } + else { + ge("hostname").focus(); + } } } @@ -257,7 +262,7 @@ private setErrorMessage(err: string, elem?: HTMLElement) { // setting error message - ge("err").textContent = err ? "Error: " + err : ""; + ge("err").textContent = err ? "Error: " + err : ""; // if DOM element was passed we're setting or removing the error indicator color if (elem) { diff --git a/UrlEditorPRO/app/popup.ts b/UrlEditorPRO/app/popup.ts index 7c4981a..1c195f2 100644 --- a/UrlEditorPRO/app/popup.ts +++ b/UrlEditorPRO/app/popup.ts @@ -20,7 +20,8 @@ module UrlEditor { var settings = new Settings(localStorage); // it is better to set variable before page view event (init) - Tracking.trackUserVariable("Version", version); + Tracking.setCustomDimension(Tracking.Dimension.Version, version); + Tracking.init(settings.trackingEnabled); var versionElem = ge("version"); diff --git a/pack_extension.bat b/pack_extension.bat new file mode 100644 index 0000000..4635f89 --- /dev/null +++ b/pack_extension.bat @@ -0,0 +1,26 @@ +@echo off +set extDir="" +set packer="%~dp0..\WinScripts\batch\ExtensionPacker.bat" + +rem if not "%1%"=="" set extDir=%1 +if not exist %extDir% ( + set extDir="UrlEditorPRO\UrlEditorPRO\app" +) + + +if not exist %extDir% ( + goto error +) + +if not exist %packer% ( + echo Packer not found %packer% + goto :eof +) + +%packer% %extDir% + +goto :eof + +:error +echo Extension directory not found: +echo %extDir%, %1 \ No newline at end of file