使用此插件
getTimeBetweenEvents
函数使用以下参数:
-
ste
(必需,字符串):“启动计时器”事件。由 Analytics“启动计时器”事件构成的以逗号分隔的字符串。 -
rt
(必需,布尔):“重新启动计时器”选项。如果希望每当events
变量包含“启动计时器”事件时便重新启动计时器,则设置为true
。如果不希望在遇到“启动计时器”事件时重新启动计时器,则设置为false
。 -
stp
(必需,字符串):“停止计时器”事件。由 Analytics“停止计时器”事件构成的以逗号分隔的字符串。 -
res
(必需,布尔):“重置计时器”选项。如果要在计时器启动时开始记录时间,并在计时器停止后重置计时器,则设置为true
。如果要记录时间但不停止计时器,则设置为false
。如果设置为false
,则在 events 变量记录到停止事件后,计时器将继续运行。TIP
如果将此参数设置为false
,则强烈建议您设置下面的rte
参数。* **`cn`**(可选,字符串):存储了首个事件的时间的 Cookie 名称。默认值为 `"s_tbe"`。
-
etd
(可选,整数):Cookie 的过期时间(以天为单位)。如果希望 Cookie 在浏览器会话结束时过期,则设置为0
。如果未设置任何值,则将使用默认值,即 1 天。 -
fmt
(可选,字符串):返回秒数时采用的时间格式(默认值为“无”)-
"s"
表示秒 -
"m"
表示分钟 -
"h"
表示小时 -
"d"
表示天 -
如果未设置,则返回值的格式将遵循以下规则:
- 若返回值小于 1 分钟,则会以“5 秒”为基准四舍五入到最接近的值。例如:10 秒、15 秒
- 若返回值介于 1 分钟和 1 小时之间,则会以“0.5 分钟”为基准四舍五入到最接近的值。例如,30.5 分钟、31 分钟
- 若返回值介于 1 小时和 1 天之间,则会以“0.25 小时”为基准四舍五入到最接近的值。例如,2.25 小时、3.5 小时
- 若返回值大于 1 天,则会以“1 天”为基准四舍五入到最接近的值。例如,1 天、3 天、9 天
-
-
bml
(可选,数字):根据fmt
参数的格式,作为四舍五入基准的时长。例如,如果fmt
参数为"s"
且此参数为2
,则返回值将以“2 秒”为基准四舍五入到最接近的值。如果fmt
参数为"m"
且此参数为0.5
,则返回值将以“0.5 分钟”为基准四舍五入到最接近的值。 -
rte
(可选,字符串):由 Analytics“删除计时器”事件构成的以逗号分隔的字符串。默认值为“无”。
调用此函数将返回一个整数,该整数代表以相应格式表示的“启动计时器”事件与“停止计时器”事件之间间隔的时长。
示例调用
// The timer starts or restarts when the events variable contains event1
// The timer stops and resets when the events variable contains event2
// The timer resets when the events variable contains event3 or the visitor closes their browser
// Sets eVar1 to the number of seconds between event1 and event2, rounded to the nearest 2-second benchmark
s.eVar1 = getTimeBetweenEvents("event1", true, "event2", true, "", 0, "s", 2, "event3");
// The timer starts when the events variable contains event1. It does NOT restart with subsequent hits that also contain event1
// The timer records a "lap" when the events variable contains event2. It does not stop the timer.
// The timer resets when the events variable contains event3 or if more than 20 days pass since the timer started
// The timer is stored in a cookie labeled "s_20"
// Sets eVar4 to the number of hours between event1 and event2, rounded to the nearest 90-minute benchmark
s.eVar4 = getTimeBetweenEvents("event1", false, "event2", false, "s_20", 20, "h", 1.5, "event3");
// Similar to the above timer in eVar4, except the return value is returned in seconds/minutes/hours/days depending on the timer length.
// The timer expires after 1 day.
s.eVar4 = getTimeBetweenEvents("event1", true, "event2", true);
版本历史记录
3.0(2021 年 3 月 19 日)
- 以上下文数据形式添加了版本号。
2.1(2018 年 5 月 26 日)
- 包含对
formatTime
插件新版本所做的更改。
2.0(2018 年 4 月 6 日)
- 对插件进行了彻底重写/再分析。