Tracking multiple hostnames with universal analytics - multiple-domains

I have one website, which can be reached under three hostnames. Each hostname has a different domain name.
For example, my website can be reached at www.example.com, www.example2.com and www.example3.com. On each the same content is served. It's duplicate content.
For each hostname I have created a universal analytics property under one account. So for example UA-XXXXXX-1, UA-XXXXXX-2 and UA-XXXXXX-3
The content which appears is identical on all hostnames. So there is only one folder on the webserver that serves the same HTML content for all hostnames.
It's like stackoverflow.com could be reached also under stackoverflow2.com and do on.
How does the tracking code have to look like, so that I collect stats for each hostname? I have tried the following javascripts, all of which won't work:
<script>
(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=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-1', {'cookieDomain': 'example.com'});
ga('create', 'UA-XXXXXX-2', {'cookieDomain': 'example2.com'});
ga('create', 'UA-XXXXXX-3', {'cookieDomain': 'example3.com'});
ga('send', 'pageview');
</script>
I also tried:
<script>
(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=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-1', 'example.com');
ga('create', 'UA-XXXXXX-2', 'example2.com');
ga('create', 'UA-XXXXXX-3', 'example3.com');
ga('send', 'pageview');
</script>
I also used named trackers in combination with cookieDomain, with no success.
How does the single javascript snippet look like in order to track the visits of all pages?

You need only one property, you can then filter views by hostname (and have rollup view to track the numbers for alle three combined). That would reduce the necessary code to
<script>
(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=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-1', 'auto');
ga('send', 'pageview');
</script>
Where the "auto" parameter to ga create means that the cookie domain is set to the current hostname.

Related

How to launch application threw "a href" on the foreground instead of background

In my project i am using "a href" to launch windows application.
<a href={`some app here`}>
//Similar logic to mailto
The problem is, that it launch it on the background instead of bringing it up on the foreground.
Basically it just sits and blinks in Windows task bar instead of automatically appear on top of the screen.
Does anyone knows is there any specific way how with a tag bring it on the foreground automatically instead of background?
You would most likely have to use javascript for this. If that is fine, use this code here:
<html>
<head>
<title>Application Executer</title>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Application Executer"
BORDER="no"
CAPTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
SCROLL="no"
WINDOWSTATE="normal">
<script type="text/javascript" language="javascript">
function RunFile() {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
}
</script>
</head>
<body>
Run the Notepad application
</body>
</html>
You would replace the notepad.exe in c:/windows/system32/notepad.exe with the application file that you want to run. Hope this helps!

Chrome - refresh HTML page, sub-pages, sub-sub-pages etc. at once

I'm making an SPA website using Polymer. My main HTML page looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<script src="/bower_components/webcomponentsjs/webcomponents.js"></script>
<script src="/bower_components/system.js/dist/system.js"></script>
<script>
System.config({
map:{
traceur: '/bower_components/traceur/traceur.min.js'
}
});
</script>
<meta charset="UTF-8">
<link rel="import" href="/html/foobar-app.html">
</head>
<body>
<foobar-app></foobar-app>
</body>
</html>
with foobar-app defined as:
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/iron-pages/iron-pages.html">
<link rel="import" href="/bower_components/paper-toast/paper-toast.html">
<link rel="import" href="/html/pages/all-territories.html">
<link rel="import" href="/html/pages/app-login.html">
<dom-module id="foobar-app">
<template>
<style></style>
<iron-pages id="pages" selected="1">
<app-login on-logged-in="onLoggedIn"></app-login>
<all-territories></all-territories>
</iron-pages>
<iron-ajax
url="http://api.foobar.com/data">
</iron-ajax>
</template>
<script>
(function() {
Polymer({
is: 'foobar-app',
// ...
});
})();
</script>
</dom-module>
When I make a change to foobar-app's code everything works fine and updates if I refresh the page. But if I make a change to one of its sub-components or to one of the sub-component's own sub-components, the related html doesn't refresh and I have to manually browse to the related HTML file and press refresh. Else, only the top HTML file is refreshed (foobar-app.html).
How can I ask Chrome to refresh the current page and all its imports, sub-imports etc. whatever the deepness?
I've tried the following without success:
Pressing CTRL + MAJ + R twice
Pressing CTRL + R twice
Try opening the inspector for this page (right click, inspect). Then right click on the refresh icon, finally select "Empty Cache and Hard Reload" from the refresh drop down.
I have had problems with IFrames doing this, but never ajax calls; but this fixed it for me.

What's the best practice for referencing 3rd parties JS library in Polymer custom element?

Currently, I face some serious problem about duplicate referencing 3rd-parties library that causes some libraries to malfunction.
This is the first custom element.
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/jquery-ui/jquery-ui.js"></script>
<dom-module id="jquery-ui-menu">
<script>
Polymer({
is: "jquery-ui-menu"
});
</script>
</dom-module>
This is the another element.
<script src="../../bower_components/jquery/dist/jquery.js"></script>
<script src="../../bower_components/jquery-ui/jquery-ui.js"></script>
<dom-module id="jquery-ui-popup">
<script>
Polymer({
is: "jquery-ui-popup"
});
</script>
</dom-module>
As you can see, both of this script tag refer to jQuery that locate in the same path. Normally, browser should load jQuery 2 times that cause some serious problem like the following code.
All registered event will be wiped out when jQuery is loaded second time.
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.js"></script>
<script type="text/javascript">
$(window).on('test', function (){alert('test!');});
</script>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.js"></script>
<script type="text/javascript">
$(window).trigger('test');
</script>
http://jsfiddle.net/sry1shpt/
I think this is not the bug of jQuery or any other 3rd-parties libraries. But it's a serious problem of Polymer. It's totally nonsense to allow element load duplicated script.
Do you have any practical way to solve this problem?
Please remember the source code of both elements may locate in difference repository and it should not know about each other.
Thanks,
You can put your <script> tags into a seperate HTML file (i.e. jquery-scripts.html) and use HTML imports in both custom elements:
<link rel="import" href="jquery-scripts.html">
HTML imports are de-duplicated and thus jquery-scripts.html and as a consequence the jquery library will only be imported once.

Why is my Google Analytics Code Getting edited when I enter it into Blogger?

After getting the needed code from Google Analytics (see below) I am entering it just before the tag in the HTML from my settings. However it CHANGES every time after I save to the garbage below with #39 tag. Why is it doing this? What can I do?
<script>
(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=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46134833-1', 'ourunitedvoice.org');
ga('send', 'pageview');
</script>
<script>
(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=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46134833-1', 'ourunitedvoice.org');
ga('send', 'pageview');
</script>
#39
is an encoded quotation mark (it seem Blogger what's to prevent you from breaking your template).
I have never used blogger but there should be no need to enter any code. According to documentation all you have to do os to enter you Analytics account id in the appropriate tab.

How do I reference my javascript files with this folder structure?

This is a very simple thing that I can't seem to get to work. What is the correct way for referencing my resources folder in my script and link tags? Is there a trick to this since my URLs are mapped to Spring resources? Do I have to do anything special since my resources folder isn't in my WEB-INF folder? Do I need to move it into the WEB-INF folder? If I do move it there, how would it be referenced inside the WEB-INF folder. I have tried everything I can think of, including....
With folder in current position -
/WebContent/resources/scripts/jquery-1.6.1.min.js
/resources/scripts/jquery-1.6.1.min.js
../resources/scripts/jquery-1.6.1.min.js
../../resources/scripts/jquery-1.6.1.min.js
/../resources/scripts/jquery-1.6.1.min.js
/../../resources/scripts/jquery-1.6.1.min.js
With folder inside WEB-INF -
/resources/scripts/jquery-1.6.1.min.js
../resources/scripts/jquery-1.6.1.min.js
../../resources/scripts/jquery-1.6.1.min.js
/../resources/scripts/jquery-1.6.1.min.js
/../../resources/scripts/jquery-1.6.1.min.js
Are any of these right?
I'm getting this in my console when I use 'resources/scripts/jquery-1.6.1.min.js' -
May 23, 2011 11:30:19 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI
[/ProjectName/resources/styles/global.css] in DispatcherServlet with name 'spring'
home.jsp -
<html>
<head>
<title>
title goes here
</title>
<script type="text/javascript" src="/WebContent/resources/scripts/global.js"></script>
<script type="text/javascript" src="/WebContent/resources/scripts/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="/WebContent/resources/styles/global.css" media="screen" />
<script type="text/javascript">
$(document).ready(
function(){
alert('hello');
});
</script>
</head>
<body>
${message}
<input id="inputField"></input>
</body>
</html>
Replace for this:
<script type="text/javascript" src="resources/scripts/global.js"></script>
<script type="text/javascript" src="resources/scripts/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="resources/styles/global.css" media="screen"