last day (14 days later) » 

6:57 AM
0
A: Changing the output of a javascript

user907860you need to change this line return tosArray[0] == 50 ? (parseInt(tosArray[1]) + 1) + ":00" : (tosArray[1] || "0") + ":" + (parseInt(tosArray[0]) + 10 ) to this one return tosArray[0] == 40 ? (parseInt(tosArray[1]) + 1) + ":00" : (tosArray[1] || "0") + ":" + (parseInt(tosArray[0]) + 20 ) an...

 
Thanks. The mess in the code is probably useful for some other part of the code. I only took out the part that I needed for this question. People can actually set the time variable themselves. How about if they set the variable to 30 seconds? I understand the above is working when I change it manually, but if someone changes the time variable on a plugin options page the output should also be accordingly.
 
@WendiT so then you might need to change total_time += 10 to += 20 accordingly
 
Do I understand it correctly when I say that the 50 and 10 and 40 and 20 are the seconds to make the minute? And the 10 and 20 are the steps to take?
 
@WendiT 10 and 20 ( I think you're asking about total_time += 10; and total_time += 20; ) I don't know what it is. I can guess that 10 and 20 a seconds and this variable is used somewhere else. As for 50 and 10 and 40 and 20, this logic takes your previous time string, for instance 1:40 splits it to an Array and reverts it, so you get [40:1] and then checks if you have 40, it adds 1 to the minute value and set seconds value to 0. So, yes, you are right, these are seconds
*correction [40, 1]
 
Yes, the total_time is needed for another function. Could you still look at the 5th comment about this one: People can actually set the time variable themselves. How about if they set the variable to 30 seconds? I understand the above is working when I change it manually, but if someone changes the time variable on a plugin options page the output should also be accordingly.
 
6:59 AM
**How about if they set the variable to 30 seconds?**
what variable do you mean? The one passed to the startTimeTracking call? startTimeTracking("00") ? So if a user passes 30 seconds it will be startTimeTracking("30") , right?
 
This is used for a WordPress plugin. The plugin has an option page where people can set the time that an event has to be fired. Standard it's 10 seconds, but if they want once every 30 secs or 60 secs it should also reflect in the output.
 
what is the name of this variable?
what should I use?
 
Hang on
ga("send", "event", "Time", "Log", tos) It's where the tos is in this line, so the output time
Maybe it's easier to download the plugin. Then you have all the scripts.
 
7:18 AM
I've updated the answer
 
Still confused if this will work. If someone sets the stLogInterval to 50 seconds, will the output by ga("send", "event", "Time", "Log", "0:50") and the next one ga("send", "event", "Time", "Log", "1:40")?
And also if someone want to fire an event every 3 minutes. How will this be done in return tosArray[0] == 40 ? (parseInt(tosArray[1]) + 1) + ":00" : (tosArray[1] || "0") + ":" + (parseInt(tosArray[0]) + 20 ) ?
 
8:05 AM
as for "If someone sets the stLogInterval to 50 seconds, will the output by ga ..."
no, the output will not be that. The logic which was present initially in your question didn't show that the variable passed by a user is the same as the interval value. You had '00' for the user value, and hardcoded 10 and 10000 for the interval;

so I still do not understand what do you want.
in your question the interval is set as a hardcode value, that is 10 and 10000, so I didn't think that these values can be supplied by the user.
the value which is supplied by the user is used only as a counter start
 
 
1 hour later…
9:33 AM
Maybe I need to understand the values in the script. In this line what does the 10 mean?
return tosArray[0] == 50 ? (parseInt(tosArray[1]) + 1) + ":00" : (tosArray[1] || "0") + ":" + (parseInt(tosArray[0]) + 10)
And in this line, what does the 10 mean?
total_time += 10;
This is the full script btw

var _gaq = _gaq || [];
var stFailbackDefaults = {
trackScrolling: true,
stLogInterval: 10,
docTitle: window.document.title,
cutOffTime: 900,
trackNoEvents: false,
trackNoMaxTime: false
};
window.total_time = 0;
var stIntervalObj = null;

function TrackingLogTime(tosArray) {
return tosArray[0] == 50 ? (parseInt(tosArray[1]) + 1) + ":00" : (tosArray[1] || "0") + ":" + (parseInt(tosArray[0]) + 10)
}

function stInitializeControlVars() {
if (typeof window.trackScrolling == "undefined") {
And people can set the stLogInterval in a php file like this
var stLogInterval=<?php
echo $rbrevent;
?>*1000;
The $rbrevent is the value people can choose themselves.
What I want is when people choose 40 seconds as the time interval the event should be send to Analytics must be ga("send", "event", "Time", "Log", "0:40") and after the next 40 seconds ga("send", "event", "Time", "Log", "1:20").
Instead of ga("send", "event", "Time", "Log", "0:10") after the first 40 seconds and ga("send", "event", "Time", "Log", "0:20") after the second 40 seconds.
 

last day (14 days later) »