Issue with tracking double google tracking code when putting a widget on external page - analytics

Putting this code at a customers site
(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-yyy', 'auto');
ga('send', 'pageview');
does not work because the customer already has same code before but with another UA-code. The code is used for tracking a widgets visitors, so it looks like this on the customers page:
(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-yyy', 'auto');
ga('send', 'pageview');
(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-xxx', 'auto');
ga('send', 'pageview');
I believe this is an issue because UA-xxx would be disabled (I don't see any realtime views on that - so that's my theory.) No console errors etc, but that's all about how google is handling this I suppose.
How is it possible to create google analytics code that won't interphere with the customers code without having the customer involved? Is it possible?
UPDATE
I've found this, but I'm not sure if I could use this without interphering with the customer: http://www.tjkelly.com/blog/google-analytics-two-tracking-codes-on-same-page-2014/

Related

Typescript Parsing error: '}' expected when trying to use Google Analytics

I am trying to add Google Analytics to my react app and I have the Script tag in the head of the HTML file but I want this part of the script to be conditionally rendered. I don't want to use any dependencies if I can help it. The code below is what I am using but I get a Parsing Error. Can anyone shed any light on my dilemma?
import React from 'react';
interface IGoogleAnalytics {
arguments?: any
}
const GoogleAnalytics: React.FC<IGoogleAnalytics> = () => {
return (
<script>
{
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};
ga.l=+new Date;
ga('create', 'UA-000000000-1', 'auto');
ga('send', 'pageview');
}
</script>
)
}
export default GoogleAnalytics
if you don't want use any dependence, so move your script tag to HTML file after Google Analytics script file.
<script src="link to Google Analytics script" />
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};
ga.l=+new Date;
ga('create', 'UA-000000000-1', 'auto');
ga('send', 'pageview');
</script>

AngularJs, UI-Router, ControllerAs & this, service/factory; Why it doesn`t work ? Where is mistake?

I am trying to use a service with a controller and UI-Router. I understand how to use it without UI-Router, and I have found a variant how to make it work with UI-Router and done it, but it doesn't work. The browser throws a mistake and I can not find where it is in my code. Maybe there is another way to use a service in ui-router, but I find this most understandable for me. Thanks!
index.html
<!DOCTYPE html>
<html>
<head>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controller.js"></script>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
<link href="bower_components/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet">
<link rel="stylesheet" href="styles/style.css">
</head>
<body ng-app="mainApp">
<div class="container-fluid">
<div ui-view></div>
</div>
</body>
</html>
try.html
<h4>{{try.articles.thereAre[1].title}}</h4>
And angularJS App with ui-router in two files: app.js and controller.js.
app.js
angular.module('mainApp', ['dndLists', 'ui.router'])
.config(function($stateProvider) {
$stateProvider
.state('try', {
url: '/try',
templateUrl: ' templates/try.html',
controller: 'tryCtrl as try'
})
})
controller.js
angular.module('mainApp')
.service('defaultArticles', function() {
var me = this;
me.thereAre = [
{
id: '1',
title: 'All Victims Are Out of the Hospit',
titleCopy: 'All Victims Are Out of the Hospit',
idea: "'We really were very lucky', Gov. Andrew M. Cuomo said after a significant blast in the Chelsea neighborhood of Manhattan. Nobody was killed, and all 29 of the injured have been released from the hospital. Remnants of the bomb and a second device were being investigated, and an additional 1,000 police officers and National Guard members were being deployed in the city.",
hide_or_no: true,
isCollapsed: true,
picture: 'src/img/1.jpg'
},
{
id: '2',
title: 'How I Spent My New York Fashion Week',
titleCopy: 'How I Spent My New York Fashion Week',
idea: 'In early September, summer turns to fall and fashion turns to New York Fashion Week, the first leg in the monthlong international relay in which next spring’s collections (or sometimes this fall’s collections) are shown. New York’s week is particularly crammed, and while I raced uptown and down, subsisting on what I could cadge from catered shows and parties — a blini-and-caviar here (Ralph Lauren), a frosted mini doughnut there (Gucci), a cherry Coke Slurpee sucked down after dark (Alexander Wang) — I filled the margins of my notebook with the obscure, unexpected and pleasantly surprising. Here are some of the most memorable things I saw.',
hide_or_no: true,
isCollapsed: true,
picture: 'src/img/2.jpg'
}
];
})
.controller('tryCtrl', function(defaultArticles) {
var me = this;
me.artickles = defaultArticles;
})
I get this mistake, what am I doing wrong?
Template expects
<h4>{{try.articles.thereAre[1].title}}</h4>
while your code uses
me.artickles = defaultArticles;
Simply "artickles" is not "articles"
Side note: I would avoid JS keywords as try in any context... just a note

No Permission error using Firebase

I am trying to add Firebase for the first time to an ionic application. I have set up my project and referenced the javascript files however when I run the application I see the error 'Error: Permission Denied'
I have not yet set up authentication in my app but, if I am understanding things properly I shouldn't need to do this while I am just testing.
My index.html contains the following:
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.2.0/angularfire.min.js"></script>
While the app.js has the following lines:
angular.module('starter', ['ionic', 'firebase'])
.factory("Items", function($firebaseArray) {
var itemsRef = new Firebase("https://todo-83e58.firebaseio.com/items");
return $firebaseArray(itemsRef);
})
.controller('ListCtrl', function($scope, $ionicListDelegate, Items) {
$scope.items = Items;
$scope.addItem = function () {
var name = prompt("what do you need to buy?");
if (name) {
$scope.items.$add({"name": name});
}
};
I would be grateful for any pointers on how to get the basics right as I have tried following the information on the Firebase site and I seem to have it all set up correctly. Am I misunderstanding the authentication or shouldI be able to write to the database without setting this up first ?
It sounds that your Security & Rules isn't giving you access to items. Please make sure to spend some time reading the S&R documentation.
If you are only testing the application and don't want to care about it now just set it to full read and write.
On the new console go to Database > Rules.
{
"rules": {
".read": true,
".write": true
}
}

Universal Google Analytics Cross Domain Tracking - Not Tracking Correctly

I have a question about setting the "Cross Domain Tracking" at Universal Analytics (analytics.js).
I have a virtual store and use the domain www.dominioA.com.br and checkout is done in another domain www.dominioB.com.br
In Google Analytics Classic (ga.js) used the following code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-99999999-9']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
In the passage from domain A to domain B that is a FORM / POST, used the following code:
_gaq.push (['_linkByPost' document.Form]);
Thus the domain B can read the cookies from the domain A and works properly the transition domain.
I'm upgrading to Universal Analytics (analytics.js) and read the instructions given in the article below:
https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain
In store pages that are in www.dominioA.com.br put the following code:
<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-99999999-9', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['www.dominioB.com.br'] );
ga('send', 'pageview');
</script>
In store pages that are in www.dominioB.com.br put the following code:
<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-99999999-9', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['www.dominioA.com.br'] );
ga('send', 'pageview');
</script>
Did so the following code is an example on "Tracking multiple domains" page below:
https://developers.google.com/analytics/devguides/collection/upgrade/reference/gajs-analyticsjs#cross-domain
This way does not work, when I change the domain A to domain B, Analytics creates a new session and places like "Traffic Sources" in "Reference" that the new session originated from the domain A.
The domain change occurs in a FORM / POST and want to keep the same session, as he did earlier with the Classic Analytics. Does anyone have any examples of this integration working? Could help me.
I've tried other variations of code, but so far without success.
Thank you.
Alexandre

Combine Google Analytics with AngularJS

How do I configure Google Universal Analytics with AngularJS and instantly see some test data from my local test environment?
The current code:
<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-XXXXXXX-X', { // I have my actual UA id here
cookieDomain: 'none'
});
</script>
</head>
I also have this one:
$rootScope.$on('$routeChangeStart', function() {
ga('set', 'page', $location.url());
});
In the Real-time section in Google Analytics Dashboard i see '0 active visitors'.
You set a page url but you don't seem to have a call to the send function
ga('send', 'pageview');
"set" merely sets fields (you can do this via a configuration object as the third parameter to the send pageview, too), you need "send" to, well, send them.

Resources