how to find active user in php

Solutions on MaxInterview for how to find active user in php by the best coders in the world

showing results for - "how to find active user in php"
Maiwenn
30 Aug 2016
1-- These queries let you define find user sessions against event data
2-- logged to Segment SQL, Snowplow, or Google BigQuery.
3-- For more details, see the full post:
4-- LINK
5
6
7--- SEGMENT SQL
8-- Finding the start of every session
9SELECT *
10  FROM (
11       SELECT *
12              LAG(sent_at,1) OVER (PARTITION BY user_id ORDER BY sent_at) AS last_event
13        FROM "your_project".tracks
14      ) last
15WHERE EXTRACT('EPOCH' FROM sent_at) - EXTRACT('EPOCH' FROM last_event) >= (60 * 10)
16   OR last_event IS NULL
17
18-- Mapping every event to its session
19SELECT *,
20       SUM(is_new_session) OVER (ORDER BY user_id, sent_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS global_session_id,
21       SUM(is_new_session) OVER (PARTITION BY user_id ORDER BY sent_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS user_session_id
22  FROM (
23       SELECT *,
24              CASE WHEN EXTRACT('EPOCH' FROM sent_at) - EXTRACT('EPOCH' FROM last_event) >= (60 * 10) 
25                     OR last_event IS NULL 
26                   THEN 1 ELSE 0 END AS is_new_session
27         FROM (
28              SELECT *,
29                     LAG(sent_at,1) OVER (PARTITION BY user_id ORDER BY sent_at) AS last_event
30                FROM "your_project".tracks
31              ) last
32       ) final
33
34
35--- SNOWPLOW
36-- Finding the start of every session
37SELECT *
38  FROM (
39       SELECT *
40              LAG(collector_tstamp,1) OVER (PARTITION BY domain_userid ORDER BY collector_tstamp) AS last_event
41        FROM "your_project".events
42      ) last
43WHERE EXTRACT('EPOCH' FROM collector_tstamp) - EXTRACT('EPOCH' FROM last_event) >= (60 * 10)
44   OR last_event IS NULL
45
46-- Mapping every event to its session
47SELECT *,
48       SUM(is_new_session) OVER (ORDER BY domain_userid, collector_tstamp ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS global_session_id,
49       SUM(is_new_session) OVER (PARTITION BY domain_userid ORDER BY collector_tstamp ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS user_session_id
50  FROM (
51       SELECT *,
52              CASE WHEN EXTRACT('EPOCH' FROM collector_tstamp) - EXTRACT('EPOCH' FROM last_event) >= (60 * 10) 
53                     OR last_event IS NULL 
54                   THEN 1 ELSE 0 END AS is_new_session
55         FROM (
56              SELECT *,
57                     LAG(collector_tstamp,1) OVER (PARTITION BY domain_userid ORDER BY collector_tstamp) AS last_event
58                FROM "your_project".events
59              ) last
60       ) final
61
62
63--- GOOGLE BIGQUERY
64-- Finding the start of every session
65SELECT * 
66  FROM (
67       SELECT *,
68              LAG(occurred_at,1) OVER (PARTITION BY fullVisitorId ORDER BY occurred_at) AS last_event
69         FROM (
70              SELECT fullVisitorId,
71                     visitStartTime + hits.time/1000 AS occurred_at
72                FROM "your_tables"
73              ) pre
74       ) last
75 WHERE occurred_at - last_event >= (60 * 10)
76    OR last_event IS NULL
77
78-- Mapping every event to its session
79SELECT *,
80       SUM(is_new_session) OVER (ORDER BY fullVisitorId, occurred_at) AS global_session_id
81  FROM (
82       SELECT *,
83              CASE WHEN occurred_at - last_event >= (60 * 10) OR last_event IS NULL THEN 1 ELSE 0 END AS is_new_session
84         FROM (
85              SELECT *,
86                     LAG(occurred_at,1) OVER (PARTITION BY fullVisitorId ORDER BY occurred_at) AS last_event
87                FROM (
88                     SELECT fullVisitorId,
89                            visitStartTime + hits.time/1000 AS occurred_at
90                       FROM "your_tables"
91                     ) pre
92              ) last
93       ) final
94 ORDER BY 1,2