Leon4gr45 commited on
Commit
bb6b85b
·
verified ·
1 Parent(s): 2621fc4

Delete test/plausible_web/controllers/api/external_stats_controller/query_time_on_page_test.exs with huggingface_hub

Browse files
test/plausible_web/controllers/api/external_stats_controller/query_time_on_page_test.exs DELETED
@@ -1,642 +0,0 @@
1
- defmodule PlausibleWeb.Api.ExternalStatsController.QueryTimeOnPageTest do
2
- use PlausibleWeb.ConnCase
3
-
4
- setup [:create_user, :create_site, :create_api_key, :use_api_key, :create_site_import]
5
-
6
- setup %{site: site} = context do
7
- FunWithFlags.enable(:new_time_on_page, for_actor: site)
8
-
9
- context
10
- end
11
-
12
- test "aggregated time_on_page metric based on engagement data", %{
13
- conn: conn,
14
- site: site
15
- } do
16
- populate_stats(site, [
17
- build(:pageview, user_id: 12, pathname: "/blog", timestamp: ~N[2021-01-01 00:00:00]),
18
- build(:engagement,
19
- user_id: 12,
20
- pathname: "/blog",
21
- timestamp: ~N[2021-01-01 00:10:00],
22
- engagement_time: 120_000
23
- ),
24
- build(:engagement,
25
- user_id: 12,
26
- pathname: "/blog",
27
- timestamp: ~N[2021-01-01 00:11:00],
28
- engagement_time: 20_000
29
- ),
30
- build(:pageview, user_id: 13, pathname: "/blog", timestamp: ~N[2021-01-01 00:10:00]),
31
- build(:engagement,
32
- user_id: 13,
33
- pathname: "/blog",
34
- timestamp: ~N[2021-01-01 00:10:00],
35
- engagement_time: 60_000
36
- )
37
- ])
38
-
39
- conn =
40
- post(conn, "/api/v2/query", %{
41
- "site_id" => site.domain,
42
- "metrics" => ["time_on_page"],
43
- "date_range" => "all",
44
- "dimensions" => ["event:page"],
45
- "include" => %{"imports" => true}
46
- })
47
-
48
- assert_matches %{
49
- "results" => [
50
- %{"dimensions" => ["/blog"], "metrics" => [100]}
51
- ],
52
- "meta" =>
53
- ^strict_map(%{
54
- "imports_included" => true
55
- })
56
- } = json_response(conn, 200)
57
- end
58
-
59
- test "aggregated time_on_page metric with imported data", %{
60
- conn: conn,
61
- site: site,
62
- site_import: site_import
63
- } do
64
- populate_stats(site, site_import.id, [
65
- build(:pageview, user_id: 12, pathname: "/blog", timestamp: ~N[2021-01-01 00:00:00]),
66
- build(:engagement,
67
- user_id: 12,
68
- pathname: "/blog",
69
- timestamp: ~N[2021-01-01 00:10:00],
70
- engagement_time: 120_000
71
- ),
72
- build(:imported_pages,
73
- page: "/blog",
74
- date: ~D[2021-01-01],
75
- visitors: 9,
76
- total_time_on_page: 9 * 20,
77
- total_time_on_page_visits: 9
78
- )
79
- ])
80
-
81
- conn =
82
- post(conn, "/api/v2/query", %{
83
- "site_id" => site.domain,
84
- "metrics" => ["time_on_page"],
85
- "date_range" => "all",
86
- "dimensions" => ["event:page"],
87
- "include" => %{"imports" => true}
88
- })
89
-
90
- assert_matches %{
91
- "results" => [
92
- %{"dimensions" => ["/blog"], "metrics" => [30]}
93
- ],
94
- "meta" =>
95
- ^strict_map(%{
96
- "imports_included" => true
97
- })
98
- } = json_response(conn, 200)
99
- end
100
-
101
- test "time_on_page time series", %{conn: conn, site: site, site_import: site_import} do
102
- populate_stats(site, site_import.id, [
103
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-01 00:00:00]),
104
- build(:engagement,
105
- user_id: 12,
106
- pathname: "/",
107
- timestamp: ~N[2021-01-01 00:03:00],
108
- engagement_time: 100_000
109
- ),
110
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-02 00:00:00]),
111
- build(:engagement,
112
- user_id: 12,
113
- pathname: "/",
114
- timestamp: ~N[2021-01-02 00:03:00],
115
- engagement_time: 100_000
116
- ),
117
- build(:pageview, user_id: 13, pathname: "/", timestamp: ~N[2021-01-02 00:00:00]),
118
- build(:engagement,
119
- user_id: 13,
120
- pathname: "/",
121
- timestamp: ~N[2021-01-02 00:10:00],
122
- engagement_time: 300_000
123
- ),
124
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-03 00:00:00]),
125
- build(:engagement,
126
- user_id: 12,
127
- pathname: "/",
128
- timestamp: ~N[2021-01-03 00:03:00],
129
- engagement_time: 100_000
130
- ),
131
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-04 00:00:00]),
132
- build(:engagement,
133
- user_id: 12,
134
- pathname: "/",
135
- timestamp: ~N[2021-01-04 00:03:00],
136
- engagement_time: 100_000
137
- ),
138
- build(:imported_pages,
139
- page: "/blog",
140
- date: ~D[2021-01-01],
141
- visitors: 9,
142
- total_time_on_page: 9 * 20,
143
- total_time_on_page_visits: 9
144
- )
145
- ])
146
-
147
- conn =
148
- post(conn, "/api/v2/query", %{
149
- "site_id" => site.domain,
150
- "metrics" => ["time_on_page"],
151
- "date_range" => ["2021-01-01", "2021-01-04"],
152
- "dimensions" => ["time:day", "event:page"],
153
- "include" => %{"imports" => true}
154
- })
155
-
156
- assert_matches %{
157
- "results" => [
158
- %{"dimensions" => ["2021-01-01", "/"], "metrics" => [100]},
159
- %{"dimensions" => ["2021-01-01", "/blog"], "metrics" => [20]},
160
- %{"dimensions" => ["2021-01-02", "/"], "metrics" => [200]},
161
- %{"dimensions" => ["2021-01-03", "/"], "metrics" => [100]},
162
- %{"dimensions" => ["2021-01-04", "/"], "metrics" => [100]}
163
- ],
164
- "meta" =>
165
- ^strict_map(%{
166
- "imports_included" => true
167
- })
168
- } = json_response(conn, 200)
169
- end
170
-
171
- describe "site.legacy_time_on_page_cutoff" do
172
- setup %{site: site, site_import: site_import} = context do
173
- populate_stats(site, site_import.id, [
174
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-01 00:00:00]),
175
- build(:engagement,
176
- user_id: 12,
177
- pathname: "/",
178
- timestamp: ~N[2021-01-01 00:02:00],
179
- engagement_time: 100_000
180
- ),
181
- build(:pageview, user_id: 12, pathname: "/blog", timestamp: ~N[2021-01-01 00:02:00]),
182
- build(:engagement,
183
- user_id: 12,
184
- pathname: "/blog",
185
- timestamp: ~N[2021-01-01 00:05:00],
186
- engagement_time: 100_000
187
- ),
188
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-01 00:05:00]),
189
- build(:engagement,
190
- user_id: 12,
191
- pathname: "/",
192
- timestamp: ~N[2021-01-01 00:10:00],
193
- engagement_time: 100_000
194
- ),
195
- build(:pageview, user_id: 12, pathname: "/blog", timestamp: ~N[2021-01-01 00:10:00]),
196
- build(:engagement,
197
- user_id: 12,
198
- pathname: "/blog",
199
- timestamp: ~N[2021-01-01 00:15:00],
200
- engagement_time: 100_000
201
- ),
202
- build(:pageview, user_id: 13, pathname: "/pricing", timestamp: ~N[2021-01-02 01:00:00]),
203
- build(:engagement,
204
- user_id: 13,
205
- pathname: "/pricing",
206
- timestamp: ~N[2021-01-02 01:02:00],
207
- engagement_time: 30_000
208
- ),
209
- build(:pageview, user_id: 14, pathname: "/", timestamp: ~N[2021-01-02 01:00:00]),
210
- build(:engagement,
211
- user_id: 14,
212
- pathname: "/",
213
- timestamp: ~N[2021-01-02 01:02:00],
214
- engagement_time: 30_000
215
- ),
216
- build(:imported_pages,
217
- page: "/blog",
218
- date: ~D[2021-01-01],
219
- visitors: 9,
220
- total_time_on_page: 9 * 20,
221
- total_time_on_page_visits: 9
222
- )
223
- ])
224
-
225
- context
226
- end
227
-
228
- test "breakdown with cutoff being before data (new time-on-page query used)", %{
229
- conn: conn,
230
- site: site
231
- } do
232
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[1970-01-01])
233
-
234
- conn =
235
- post(conn, "/api/v2/query", %{
236
- "site_id" => site.domain,
237
- "metrics" => ["time_on_page"],
238
- "date_range" => "all",
239
- "dimensions" => ["event:page"],
240
- "include" => %{
241
- "imports" => true
242
- }
243
- })
244
-
245
- assert_matches %{
246
- "results" => [
247
- %{"dimensions" => ["/"], "metrics" => [115]},
248
- # (2 * 100s + 9 * 20s) / 10 = 38
249
- %{"dimensions" => ["/blog"], "metrics" => [38]},
250
- %{"dimensions" => ["/pricing"], "metrics" => [30]}
251
- ],
252
- "meta" =>
253
- ^strict_map(%{
254
- "imports_included" => true
255
- })
256
- } = json_response(conn, 200)
257
- end
258
-
259
- test "breakdown with cutoff being after data (legacy query used)", %{conn: conn, site: site} do
260
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2021-01-05])
261
-
262
- conn =
263
- post(conn, "/api/v2/query", %{
264
- "site_id" => site.domain,
265
- "metrics" => ["time_on_page"],
266
- "date_range" => "all",
267
- "dimensions" => ["event:page"],
268
- "include" => %{
269
- "imports" => true
270
- }
271
- })
272
-
273
- assert_matches %{
274
- "results" => [
275
- %{"dimensions" => ["/"], "metrics" => [420]},
276
- %{"dimensions" => ["/blog"], "metrics" => [180]},
277
- %{"dimensions" => ["/pricing"], "metrics" => [nil]}
278
- ],
279
- "meta" =>
280
- ^strict_map(%{
281
- "imports_included" => true,
282
- "metric_warnings" => %{
283
- "time_on_page" => %{
284
- "code" => "legacy_time_on_page_used",
285
- "message" =>
286
- "This period includes data calculated with the legacy time on page method up to 2021-01-05"
287
- }
288
- }
289
- })
290
- } = json_response(conn, 200)
291
- end
292
-
293
- test "breakdown with cutoff being mid-data (two queries joined)", %{conn: conn, site: site} do
294
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2021-01-02])
295
-
296
- conn =
297
- post(conn, "/api/v2/query", %{
298
- "site_id" => site.domain,
299
- "metrics" => ["time_on_page"],
300
- "date_range" => "all",
301
- "dimensions" => ["event:page"],
302
- "include" => %{
303
- "imports" => true
304
- }
305
- })
306
-
307
- assert_matches %{
308
- "results" => [
309
- %{"dimensions" => ["/"], "metrics" => [225]},
310
- %{"dimensions" => ["/blog"], "metrics" => [180]},
311
- %{"dimensions" => ["/pricing"], "metrics" => [30]}
312
- ],
313
- "meta" =>
314
- ^strict_map(%{
315
- "imports_included" => true,
316
- "metric_warnings" => %{
317
- "time_on_page" => %{
318
- "code" => "legacy_time_on_page_used",
319
- "message" =>
320
- "This period includes data calculated with the legacy time on page method up to 2021-01-02"
321
- }
322
- }
323
- })
324
- } = json_response(conn, 200)
325
- end
326
-
327
- test "breakdown with cutoff being mid-data (two queries joined), no imports", %{
328
- conn: conn,
329
- site: site
330
- } do
331
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2021-01-02])
332
-
333
- conn =
334
- post(conn, "/api/v2/query", %{
335
- "site_id" => site.domain,
336
- "metrics" => ["time_on_page"],
337
- "date_range" => "all",
338
- "dimensions" => ["event:page"]
339
- })
340
-
341
- assert_matches %{
342
- "results" => [
343
- %{"dimensions" => ["/"], "metrics" => [225]},
344
- %{"dimensions" => ["/blog"], "metrics" => [180]},
345
- %{"dimensions" => ["/pricing"], "metrics" => [30]}
346
- ],
347
- "meta" =>
348
- ^strict_map(%{
349
- "metric_warnings" => %{
350
- "time_on_page" => %{
351
- "code" => "legacy_time_on_page_used",
352
- "message" =>
353
- "This period includes data calculated with the legacy time on page method up to 2021-01-02"
354
- }
355
- }
356
- })
357
- } = json_response(conn, 200)
358
- end
359
-
360
- test "aggregation with cutoff being after data (legacy query used)", %{conn: conn, site: site} do
361
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2021-01-05])
362
-
363
- conn =
364
- post(conn, "/api/v2/query", %{
365
- "site_id" => site.domain,
366
- "metrics" => ["time_on_page"],
367
- "date_range" => "all",
368
- "filters" => [["is", "event:page", ["/blog"]]],
369
- "include" => %{
370
- "imports" => true
371
- }
372
- })
373
-
374
- assert_matches %{
375
- "results" => [
376
- %{"dimensions" => [], "metrics" => [180]}
377
- ],
378
- "meta" =>
379
- ^strict_map(%{
380
- "imports_included" => true,
381
- "metric_warnings" => %{
382
- "time_on_page" => %{
383
- "code" => "legacy_time_on_page_used",
384
- "message" =>
385
- "This period includes data calculated with the legacy time on page method up to 2021-01-05"
386
- }
387
- }
388
- })
389
- } = json_response(conn, 200)
390
- end
391
-
392
- test "aggregation with cutoff being mid-data (two queries joined)", %{conn: conn, site: site} do
393
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2021-01-02])
394
-
395
- conn =
396
- post(conn, "/api/v2/query", %{
397
- "site_id" => site.domain,
398
- "metrics" => ["time_on_page"],
399
- "date_range" => "all",
400
- "filters" => [["is", "event:page", ["/blog"]]],
401
- "include" => %{
402
- "imports" => true
403
- }
404
- })
405
-
406
- assert_matches %{
407
- "results" => [
408
- %{"dimensions" => [], "metrics" => [180]}
409
- ],
410
- "meta" =>
411
- ^strict_map(%{
412
- "imports_included" => true,
413
- "metric_warnings" => %{
414
- "time_on_page" => %{
415
- "code" => "legacy_time_on_page_used",
416
- "message" =>
417
- "This period includes data calculated with the legacy time on page method up to 2021-01-02"
418
- }
419
- }
420
- })
421
- } = json_response(conn, 200)
422
- end
423
-
424
- test "aggregation with cutoff being mid-data (two queries joined), no imports", %{
425
- conn: conn,
426
- site: site
427
- } do
428
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2021-01-02])
429
-
430
- conn =
431
- post(conn, "/api/v2/query", %{
432
- "site_id" => site.domain,
433
- "metrics" => ["time_on_page"],
434
- "date_range" => "all",
435
- "filters" => [["is", "event:page", ["/blog"]]]
436
- })
437
-
438
- assert_matches %{
439
- "results" => [
440
- %{"dimensions" => [], "metrics" => [180]}
441
- ],
442
- "meta" =>
443
- ^strict_map(%{
444
- "metric_warnings" => %{
445
- "time_on_page" => %{
446
- "code" => "legacy_time_on_page_used",
447
- "message" =>
448
- "This period includes data calculated with the legacy time on page method up to 2021-01-02"
449
- }
450
- }
451
- })
452
- } = json_response(conn, 200)
453
- end
454
- end
455
-
456
- describe "legacy time_on_page metric" do
457
- test "aggregated", %{conn: conn, site: site, site_import: site_import} do
458
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2100-01-01])
459
-
460
- populate_stats(site, site_import.id, [
461
- build(:pageview, pathname: "/A", user_id: 111, timestamp: ~N[2021-01-01 00:00:00]),
462
- build(:pageview, pathname: "/B", user_id: 111, timestamp: ~N[2021-01-01 00:01:00]),
463
- build(:pageview, pathname: "/A", user_id: 999, timestamp: ~N[2021-01-02 00:00:00]),
464
- build(:pageview, pathname: "/B", user_id: 999, timestamp: ~N[2021-01-02 00:01:30]),
465
- # These are ignored for time_on_page metric
466
- build(:imported_pages, page: "/A", total_time_on_page: 40, date: ~D[2021-01-01]),
467
- build(:imported_pages, page: "/B", total_time_on_page: 499, date: ~D[2021-01-01])
468
- ])
469
-
470
- conn =
471
- post(conn, "/api/v2/query", %{
472
- "site_id" => site.domain,
473
- "metrics" => ["visitors", "time_on_page"],
474
- "date_range" => "all",
475
- "filters" => [["is", "event:page", ["/A"]]],
476
- "include" => %{
477
- "imports" => true
478
- }
479
- })
480
-
481
- assert json_response(conn, 200)["results"] == [
482
- %{"dimensions" => [], "metrics" => [3, 75]}
483
- ]
484
- end
485
-
486
- test "breakdown", %{conn: conn, site: site, site_import: site_import} do
487
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2100-01-01])
488
-
489
- populate_stats(site, site_import.id, [
490
- build(:pageview, pathname: "/A", user_id: 111, timestamp: ~N[2021-01-01 00:00:00]),
491
- build(:pageview, pathname: "/B", user_id: 111, timestamp: ~N[2021-01-01 00:01:00]),
492
- build(:pageview, pathname: "/A", user_id: 999, timestamp: ~N[2021-01-02 00:00:00]),
493
- build(:pageview, pathname: "/B", user_id: 999, timestamp: ~N[2021-01-02 00:01:30]),
494
- build(:pageview, pathname: "/C", user_id: 999, timestamp: ~N[2021-01-02 00:02:00]),
495
- build(:imported_pages, page: "/A", total_time_on_page: 40, date: ~D[2021-01-01]),
496
- build(:imported_pages, page: "/B", total_time_on_page: 499, date: ~D[2021-01-01])
497
- ])
498
-
499
- conn =
500
- post(conn, "/api/v2/query", %{
501
- "site_id" => site.domain,
502
- "metrics" => ["visitors", "time_on_page"],
503
- "date_range" => "all",
504
- "dimensions" => ["event:page"],
505
- "include" => %{
506
- "imports" => true
507
- }
508
- })
509
-
510
- assert json_response(conn, 200)["results"] == [
511
- %{"dimensions" => ["/A"], "metrics" => [3, 63]},
512
- %{"dimensions" => ["/B"], "metrics" => [3, 264]},
513
- %{"dimensions" => ["/C"], "metrics" => [1, nil]}
514
- ]
515
- end
516
-
517
- test "ignores page refresh", %{conn: conn, site: site} do
518
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2100-01-01])
519
-
520
- populate_stats(site, [
521
- build(:pageview, user_id: 123, timestamp: ~N[2021-01-01 00:00:00], pathname: "/"),
522
- build(:pageview, user_id: 123, timestamp: ~N[2021-01-01 00:01:00], pathname: "/"),
523
- build(:pageview, user_id: 123, timestamp: ~N[2021-01-01 00:02:00], pathname: "/"),
524
- build(:pageview, user_id: 123, timestamp: ~N[2021-01-01 00:03:00], pathname: "/exit")
525
- ])
526
-
527
- conn =
528
- post(conn, "/api/v2/query", %{
529
- "site_id" => site.domain,
530
- "metrics" => ["visitors", "time_on_page"],
531
- "date_range" => "all",
532
- "filters" => [["is", "event:page", ["/"]]]
533
- })
534
-
535
- assert json_response(conn, 200)["results"] == [
536
- %{"dimensions" => [], "metrics" => [1, 180]}
537
- ]
538
- end
539
- end
540
-
541
- describe "timeseries" do
542
- setup %{site: site} = context do
543
- populate_stats(site, [
544
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-01 00:00:00]),
545
- build(:engagement,
546
- user_id: 12,
547
- pathname: "/",
548
- timestamp: ~N[2021-01-01 00:05:00],
549
- engagement_time: 100_000
550
- ),
551
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-02 00:00:00]),
552
- build(:engagement,
553
- user_id: 12,
554
- pathname: "/",
555
- timestamp: ~N[2021-01-02 00:05:00],
556
- engagement_time: 200_000
557
- ),
558
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-03 00:00:00]),
559
- build(:engagement,
560
- user_id: 12,
561
- pathname: "/",
562
- timestamp: ~N[2021-01-03 00:05:00],
563
- engagement_time: 250_000
564
- ),
565
- build(:pageview, user_id: 12, pathname: "/", timestamp: ~N[2021-01-04 00:00:00]),
566
- build(:engagement,
567
- user_id: 12,
568
- pathname: "/",
569
- timestamp: ~N[2021-01-04 00:05:00],
570
- engagement_time: 200_000
571
- ),
572
- build(:pageview, user_id: 13, pathname: "/", timestamp: ~N[2021-01-04 00:00:00]),
573
- build(:engagement,
574
- user_id: 13,
575
- pathname: "/",
576
- timestamp: ~N[2021-01-04 00:05:00],
577
- engagement_time: 100_000
578
- )
579
- ])
580
-
581
- context
582
- end
583
-
584
- test "reports average new time-on-page per day", %{conn: conn, site: site} do
585
- conn =
586
- post(conn, "/api/v2/query", %{
587
- "site_id" => site.domain,
588
- "metrics" => ["time_on_page"],
589
- "date_range" => ["2021-01-01", "2021-01-04"],
590
- "filters" => [["is", "event:page", ["/"]]],
591
- "dimensions" => ["time:day"]
592
- })
593
-
594
- assert json_response(conn, 200)["results"] == [
595
- %{"dimensions" => ["2021-01-01"], "metrics" => [100]},
596
- %{"dimensions" => ["2021-01-02"], "metrics" => [200]},
597
- %{"dimensions" => ["2021-01-03"], "metrics" => [250]},
598
- %{"dimensions" => ["2021-01-04"], "metrics" => [150]}
599
- ]
600
- end
601
-
602
- test "reports legacy time-on-page as nulls per day", %{conn: conn, site: site} do
603
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2100-01-01])
604
-
605
- conn =
606
- post(conn, "/api/v2/query", %{
607
- "site_id" => site.domain,
608
- "metrics" => ["time_on_page"],
609
- "date_range" => ["2021-01-01", "2021-01-04"],
610
- "filters" => [["is", "event:page", ["/"]]],
611
- "dimensions" => ["time:day"]
612
- })
613
-
614
- assert json_response(conn, 200)["results"] == [
615
- %{"dimensions" => ["2021-01-01"], "metrics" => [nil]},
616
- %{"dimensions" => ["2021-01-02"], "metrics" => [nil]},
617
- %{"dimensions" => ["2021-01-03"], "metrics" => [nil]},
618
- %{"dimensions" => ["2021-01-04"], "metrics" => [nil]}
619
- ]
620
- end
621
-
622
- test "respects `legacy_time_on_page_cutoff`", %{conn: conn, site: site} do
623
- site = Plausible.Sites.update_legacy_time_on_page_cutoff!(site, ~D[2021-01-03])
624
-
625
- conn =
626
- post(conn, "/api/v2/query", %{
627
- "site_id" => site.domain,
628
- "metrics" => ["time_on_page"],
629
- "date_range" => ["2021-01-01", "2021-01-04"],
630
- "filters" => [["is", "event:page", ["/"]]],
631
- "dimensions" => ["time:day"]
632
- })
633
-
634
- assert json_response(conn, 200)["results"] == [
635
- %{"dimensions" => ["2021-01-01"], "metrics" => [nil]},
636
- %{"dimensions" => ["2021-01-02"], "metrics" => [nil]},
637
- %{"dimensions" => ["2021-01-03"], "metrics" => [250]},
638
- %{"dimensions" => ["2021-01-04"], "metrics" => [150]}
639
- ]
640
- end
641
- end
642
- end