Piwik trackPageView 2 different results - matomo

I want to know about the trackPageView function,
There are 2 different results on the trackPageView function. The difference occurs when using a variable in the callback.
The variable is empty,
first :
_paq.push(['trackPageView','Variable']);
The Variable 's avg_time_on_page result is always 1 sec.
second :
_paq.push(['trackPageView']);
It's default, without arguments, the avg_time_on_page result is correct.
<script type="text/javascript">
var _paq = _paq || [];
var pid = '<?php echo $postid;?>';
_paq.push(['trackPageView',pid]);
_paq.push(['trackPageView']);
_paq.push(['trackEvent', 'arcpost', 'wsite', pid]);
_paq.push(['enableLinkTracking']);
(function() {
var u="<?php echo JSPIWIK_URL;?>";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', <?php echo JSPIWIK_SITEID;?>]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
</script>
default:
PAGE NAME :The boys, please... AVG. TIME ON PAGE: 55s
var: gubof1
PAGE NAME :gubof1 AVG. TIME ON PAGE: 1s
How is this possible?

Related

save rootscope value in the project

I have a task to store a model value in my Electron Angular project . The rootscope model is binding the file path value .
I want to save this path on my project and every time when user will open this app by default it will be present there
$rootScope.Path = user_path[0];
I want to save this $rootScope.Path and make the data persist on that location everytime.
Any way to achieve this in electron/node.js ?
EDIT:-
$rootScope.fPath = "C:\\";
/*Configure FILE path*/
const {dialog} = require('electron').remote;
$scope.getFile = function(){
var file_path = dialog.showOpenDialog({
properties: ['openDirectory']
});
console.log(file_path);
$rootScope.fPath = file_path[0] + "\\bin";
I want to make this $rootScope.fPath path persist whenever I will open my app the previous selected path must be there already. So that I don't have to make further changes.
having a code snippet helps... is this what you're looking for ??
var app = angular.module('myApp', []);
app.run(function($rootScope) {
$rootScope.fpath = 'http://someSite/someFile';
});
app.controller('myCtrl', function($scope, $rootScope) {
console.log("fpath:" + $rootScope.fpath);
$scope.getFile = function(){
var file_path = dialog.showOpenDialog({
properties: ['openDirectory']
});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<div ng-app="myApp">
<p>The fPath as defined globally: <mark>{{fpath}} </mark></p>
<div ng-controller="myCtrl">
<p>The fPath as when accessed in the controller: <mark>{{fpath}}</mark> </p>
</div>
</div>

Piwik tracking code

I am adding piwik script into my website. And I have added the trackingcode js file ie
if(domains && tracker_url && site_id ) {
var _paq = _paq || [];
_paq.push(["setDomains", [domains]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u= tracker_url;
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', site_id]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
}
My question is do we need to include any piwik files other than this? ie whether we need to include the piwik.js file and all? Is there any package that is to be included into web root?
No, there is nothing else that needs to be included.
The tracking code loads the piwik.js (asynchronously) which then includes everything needed for the tracking.

Updating HTML in Angular is not working

I am still learning angular and in my example projekt I have a problem on updating the view.
Got this in my header ....
<meta charset="UTF-8">
<title>{{ name }}</title>
And this in my body:
<body ng-controller="BodyController as body">
<input type="button" ng-click="changeTitle()" name="changeNameButton" value="change name"/>
This is my head controller:
myApp.controller('HeadController',
['$scope', 'ApplicationService', 'DataService', 'UserService', function ($scope, ApplicationService, DataService, UserService) {
var self = this;
$scope.name = ApplicationService.getTitle();
}]
);
And here is my body controller:
myApp.controller('BodyController', ['$scope', 'ApplicationService', function ($scope, ApplicationService) {
$scope.text = 'Hello, Angular fanatic.';
$scope.changeTitle = function () {
console.log('change the title');
ApplicationService.setTitle('test');
}
}]);
This is my application service
myApp.service('ApplicationService', ['ConfigurationService', function(ConfigurationService){
this.title = '';
this.setTitle = function (newTitle) {
console.log('new title (setter): ' + this.title);
this.title = newTitle
}
this.getTitle = function () {
if(this.title==''){
this.title = ConfigurationService.title + ' | ' + ConfigurationService.subtitle;
}
console.log('new title (getter): ' + this.title);
return this.title;
}
}]);
So far so good and sorry that I do not use codepen, etc. But it was not working in it, ...
My Problem: It is setting the title on initial load of the website, but not on pressing the button. The new name is set to ApplicationService.title, but header controller does not update it. Whats is wrong in this case? How can I update the title in the view...?
Regards
n00n
see the codepen for it: https://codepen.io/n00n/pen/bqaGKY
What you're doing is the equivalent of the following simple code:
//in the header controller
var name = service.getTitle();
// in the header template
display(name);
// later, in the body
service.setTitle('test');
// in the header template
display(name);
You see that this can't work: the variable name in the header controller has been initialized when the controller was created, and assigning a new value to the title stored in the service can't magically change the value of the name variable in the header controller. What you want is to display the title in the service:
<title>{{ getTitle() }}</title>
$scope.getTitle = function() {
return ApplicationService.getTitle();
};
That didn't work because you're calling getTitle method when title wasn't set. So that's it is referring to older title('undefined'). You can change your binding to
$scope.getTitle = ApplicationService.getTitle;
And then change HTML to
{{getTitle()}}
So title will get fetch from service and updated on the page on each digest cycle.
Other thing which I'd like to mention is, don't use(mix) $scope when you are using controllerAs, so then remove $scope from controller and bind data to below
var vm = this;
vm.getTitle = ApplicationService.getTitle;

Opencpu and Meteor

I have seen some examples of using opencpu together with angular, but no examples of using opencpu in meteor (where angular could be inplemented easily).
Is it as easy as just including ocpu.seturl and jquery.min.js in meteor (as is done here), or does one need to think differently in meteor when using opencpu?
For example, there might be some conflicts between angular and meteor.
I know that is a diffuse question, but I've seen that I'm not the only one who does wonder about it.
Related:
https://groups.google.com/forum/#!topic/opencpu/rEi7lMK65GU
https://www.quora.com/Is-it-possible-to-call-the-R-server-within-a-website-made-with-Meteor-run-some-R-code-then-display-its-output
For example (thanks to http://jsfiddle.net/ramnathv/uatjd/15/):
var myApp = angular.module('myApp', ['angular-meteor']); //added 'angular-meteor'
//set CORS to call "stocks" package on public server
ocpu.seturl("//public.opencpu.org/ocpu/library/graphics/R")
myApp.factory('OpenCPU', function($http){
return {
Dist: function(dist){
var url = "http://public.opencpu.org//ocpu/library/stats/R/" + dist +
"/json"
return $http.post(url, {n: 100})
}
}
})
myApp.controller("HistCtrl", function($scope, $http, OpenCPU){
$scope.dist = 'rnorm'
$scope.dists = ['rnorm', 'runif']
$scope.color = 'blue'
$scope.colors = ['blue', 'red', 'darkmagenta']
$scope.breaks = 10
$scope.submit = function(){
var req = $("#plotdiv").rplot("hist", {
x : $scope.data,
col: $scope.color,
breaks: Math.floor($scope.breaks),
main: $scope.main
});
}
$scope.$watchCollection('[main, color, breaks, data]', function(x){
$scope.submit()
})
$scope.$watch('dist', function(newDist){
OpenCPU.Dist(newDist).success(function(result){
$scope.data = result
})
})
})
Would the above be a "correct" starting point? How should one declare dependencies in meteor (i.e. opencpu, jquery.min.js) ? New to meteor so any suggestions are highly appreciated!
Not using angular (not sure why one would need that), but here is a super basic setup in meteor:
HTML:
<head>
<title>opencpu</title>
<script src="//cdn.opencpu.org/opencpu-0.4.js"></script>
</head>
<body>
<h1>Testing OpenCPU</h1>
{{> hello}}
</body>
<template name="hello">
</template>
JS:
if (Meteor.isClient) {
Template.hello.onRendered(function() {
// ocpu.seturl("//public.opencpu.org/ocpu/library/graphics/R");
// couldn't come up with a good example for this
ocpu.seturl("//public.opencpu.org/ocpu/library/stats/R")
// this gives me a CORS error but the below still seems to work
console.log(ocpu);
var req1 = ocpu.call("rnorm", {n: 100}, function(session1){
var req2 = ocpu.call("var", {x : session1}, function(session2){
session2.getObject(function(data){
alert("Variance equals: " + data);
});
});
});
});
}
All I know about opencpu I've learned in the last 30 minutes -- little! So I don't know how to get past the CORS error. That error doesn't seem to happen when pointing at the graphics package, but for that one I couldn't think of a good example.

How can I convert seconds to miniutes and seconds using filters in angularjs?

I want to convert the seconds to minutes and seconds using angular js filters can any body help me .
demo
app.filter('toMinSec', function(){
return function(input){
var minutes = parseInt(input/60, 10);
var seconds = input%60;
return minutes+' minutes'+(seconds ? ' and '+seconds+' seconds' : '');
}
})
A simple filter for your requirement is as shown below.. you just need to fetch minutes with /60 and seconds using %60. Providing an extra check for bad inputs.
var app = angular.module('app', []);
app.filter('secondsToMinute', function(){
return function(timeInSeconds){
if(isNaN(timeInSeconds)){
return 'bad time. Enter time in seconds';
}else{
var minuteValue = parseInt(timeInSeconds/60);
var secondsValue = timeInSeconds%60;
}
return minuteValue + 'min, ' + secondsValue + 'sec';
}
});
app.controller('timeController', function($scope){
$scope.goodTime = 1254;
$scope.badTime = "some time";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<div ng-app="app" ng-controller="timeController">
<div> Good Time is --> {{goodTime | secondsToMinute}}</div>
<div> Bad Time is --> {{badTime | secondsToMinute}}</div>
</div>

Resources