Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Modules/Front/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ public function docs()
return response()->redirectTo('https://docs.abrouter.com')->send();
}

public function stats()
public function stats(Request $request)
{
if ($request->hasValidSignature()){
return view('front::dashboard/stats');
}

$this->enforceAuth();
return view('front::dashboard/stats');
}

public function experimentStats()
public function experimentStats(Request $request)
{
if ($request->hasValidSignature()) {
return view('front::dashboard/experiment-stats');
}

$this->enforceAuth();
return view('front::dashboard/experiment-stats');
}
Expand Down
34 changes: 27 additions & 7 deletions Modules/Front/Resources/views/dashboard/experiment-stats.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
use Modules\Front\Internal\User;
use Modules\Front\Assets\Puller;
use Illuminate\Support\Facades\URL;
?>
@extends('front::layouts.settings')

Expand Down Expand Up @@ -105,12 +105,17 @@ class="date__input date-range"
Add a tag
</button>
</form>
<a href="/en/stats/customization-event" class="track__add">
Add events
<svg class="track__add-icon">
<use href="/img/icons/icons.svg#arrow-blue"></use>
</svg>
</a>
@if(\Modules\Front\Internal\User::isAuthorized())
<button class="track__add" id="share_page">
Share page
</button>
<a href="/en/stats/customization-event" class="track__add">
Add events
<svg class="track__add-icon">
<use href="/img/icons/icons.svg#arrow-blue"></use>
</svg>
</a>
@endif
</div>
<div class="track__tags">

Expand Down Expand Up @@ -218,6 +223,21 @@ class="date__input date-range"
window.token='Bearer <?=request()->cookie('token')?>';
window.onload = $('.loader').show();
window.mode = 'experiment_stats';
<?php if (User::isAuthorized()):?>
window.url = getShareUrl();

function getShareUrl() {
return '<?=URL::temporarySignedRoute(
'experiment-stats', now()->addMinutes(30),
[
'userId' => User::me()['data']['id'],
'experimentId' => request()->get('experimentId'),
'dateFrom' => request()->get('dateFrom'),
'dateTo' => request()->get('dateTo')
])
?>';
}
<?php endif;?>
</script>
<script src="/js/Stats.js"></script>
@endsection
33 changes: 28 additions & 5 deletions Modules/Front/Resources/views/dashboard/stats.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?php
use Illuminate\Support\Facades\URL;
use Modules\Front\Internal\User;
?>
@extends('front::layouts.settings')

@section('settings')
Expand Down Expand Up @@ -31,11 +35,16 @@ class="date__input date-range"
>
</div>
</form>
<a href="/en/stats/customization-event" class="track__add">
Add events <svg class="track__add-icon">
<use href="/img/icons/icons.svg#arrow-blue"></use>
</svg>
</a>
@if(\Modules\Front\Internal\User::isAuthorized())
<button class="track__add" id="share_page">
Share page
</button>
<a href="/en/stats/customization-event" class="track__add">
Add events <svg class="track__add-icon">
<use href="/img/icons/icons.svg#arrow-blue"></use>
</svg>
</a>
@endif
</div>

<table class="table table_info" id="stats_info">
Expand Down Expand Up @@ -116,6 +125,20 @@ class="date__input date-range"
window.token='Bearer <?=request()->cookie('token')?>';
window.onload = $('.loader').show();
window.mode = 'stats';
<?php if (User::isAuthorized()):?>
window.url = getShareUrl();

function getShareUrl() {
return '<?=URL::temporarySignedRoute(
'stats', now()->addMinutes(30),
[
'userId' => User::me()['data']['id'],
'dateFrom' => request()->get('dateFrom'),
'dateTo' => request()->get('dateTo')
])
?>';
}
<?php endif;?>
</script>
<script src="/js/Stats.js"></script>
@endsection
2 changes: 2 additions & 0 deletions Modules/Front/Resources/views/layouts/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<a href="/" class="header-profile__logo">
<picture><source srcset="/img/logo.svg" type="image/webp"><img src="/img/logo.svg" alt="Logo"></picture>
</a>
@if(\Modules\Front\Internal\User::isAuthorized())
<button type="button" class="menu__icon icon-menu"><span></span></button>
<div class="header-profile__menu">
<div class="header-profile__token token-header">
Expand Down Expand Up @@ -64,6 +65,7 @@
</div>
</div>
</div>
@endif
</div>
</header>
@endsection
Expand Down
6 changes: 4 additions & 2 deletions Modules/Front/Routes/web.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Routing\Router;

Expand Down Expand Up @@ -29,9 +30,10 @@
$router->get('/en/feature-toggle', 'DashboardController@featureToggle');
$router->get('/en/feature-toggle/run-feature-flag', 'DashboardController@runFeatureFlag');
$router->get('/en/docs', 'DashboardController@docs');
$router->get('/en/stats', 'DashboardController@stats');
$router->get('/en/stats', 'DashboardController@stats')->name('stats');
$router->get('/en/stats/customization-event', 'CustomizationEventController@index');
$router->get('/en/board/experiment-stats', 'DashboardController@experimentStats');
$router->get('/en/board/experiment-stats', 'DashboardController@experimentStats')
->name('experiment-stats');
$router->get('/en/board/run-experiment', 'DashboardController@runExperiment');
$router->get('/en/user-page', 'DashboardController@userPage');

Expand Down
87 changes: 73 additions & 14 deletions public/js/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ function getEvents (counters, percentage = []) {
function getFunnelStats (
dateFrom,
dateTo,
dateIntervals
dateIntervals,
userId
) {
$.ajax({
'method': "POST",
'url': "/api/v1/event/funnel?filter[date_from]="+ dateFrom +"&filter[date_to]="+ dateTo,
'headers': {
'Authorization': window.token,
},
'data': {
'userId': userId
},
'success': function (response) {
$('.loader').hide();
$('.table__thead').show();
Expand Down Expand Up @@ -130,7 +134,8 @@ function getExperimentStats (
dateFrom,
dateTo,
backgroundBranchColors,
tag = ''
userId,
tag = '',
) {
$.ajax({
'method': "GET",
Expand All @@ -141,6 +146,9 @@ function getExperimentStats (
'headers': {
'Authorization': window.token
},
'data': {
'userId': userId
},
'success': function (response) {
$('.loader').hide();
$('.dashboard__labels').children().remove();
Expand Down Expand Up @@ -625,18 +633,42 @@ function getDateIntervals(id, startDate, endDate) {
}

$(document).ready(function () {
let url = new URL(window.location.href),
dateFrom = url.searchParams.get('dateFrom'),
dateTo = url.searchParams.get('dateTo'),
dateInterval,
dateSplit,
userId = new URL(window.location.href).searchParams.get('userId');

const shareData = {
url: window.url
}

$(document).on('click', '#share_page', function () {
navigator.share(shareData);
})

getDateIntervals(
'.date-range[name="dates"]',
moment().subtract(6, "days").format('MMM DD, YYYY'),
moment().format('MMM DD, YYYY')
dateFrom ?? moment().subtract(6, "days").format('MMM DD, YYYY'),
dateTo ?? moment().format('MMM DD, YYYY')
)

let dateInterval = $('#date_filter_experiment').val() ?? $('#date_stats').val(),
if (
dateFrom === null &&
dateTo === null
) {
dateInterval = $('#date_filter_experiment').val() ?? $('#date_stats').val(),
dateSplit = dateInterval.split('-'),
dateFrom = convertDate(dateSplit[0]),
dateTo = convertDate(dateSplit[1]),
dateIntervals = getDateInterval(dateFrom, dateTo),
url = new URL(window.location.href),
dateTo = convertDate(dateSplit[1]);

url.searchParams.set('dateFrom', dateFrom);
url.searchParams.set('dateTo', dateTo);
window.history.replaceState({}, '', url);
}

let dateIntervals = getDateInterval(dateFrom, dateTo),
experimentId = url.searchParams.get("experimentId"),
backgroundBranchColors = [
'#F07D5F',
Expand All @@ -653,7 +685,8 @@ $(document).ready(function () {
? getFunnelStats(
dateFrom,
dateTo,
dateIntervals
dateIntervals,
userId
)
: (
getTags(),
Expand All @@ -662,7 +695,8 @@ $(document).ready(function () {
dateIntervals,
dateFrom,
dateTo,
backgroundBranchColors
backgroundBranchColors,
userId
)
)

Expand All @@ -683,10 +717,15 @@ $(document).ready(function () {
dateTo = convertDate(dateSplit[1]),
dateIntervals = getDateInterval(dateFrom, dateTo);

url.searchParams.set('dateFrom', dateFrom);
url.searchParams.set('dateTo', dateTo);
window.history.replaceState({}, '', url);

getFunnelStats(
dateFrom,
dateTo,
dateIntervals
dateIntervals,
userId
)

load = 0;
Expand All @@ -711,10 +750,15 @@ $(document).ready(function () {
dateTo = convertDate(dateSplit[1]),
dateIntervals = getDateInterval(dateFrom, dateTo);

url.searchParams.set('dateFrom', dateFrom);
url.searchParams.set('dateTo', dateTo);
window.history.replaceState({}, '', url);

getFunnelStats(
dateFrom,
dateTo,
dateIntervals
dateIntervals,
userId
)

load = 0;
Expand All @@ -739,14 +783,19 @@ $(document).ready(function () {
dateTo = convertDate(dateSplit[1]),
dateIntervals = getDateInterval(dateFrom, dateTo);

url.searchParams.set('dateFrom', dateFrom);
url.searchParams.set('dateTo', dateTo);
window.history.replaceState({}, '', url);

$('.table.table_ap').remove();

getExperimentStats(
experimentId,
dateIntervals,
dateFrom,
dateTo,
backgroundBranchColors
backgroundBranchColors,
userId
)

load = 0;
Expand All @@ -771,14 +820,19 @@ $(document).ready(function () {
dateTo = convertDate(dateSplit[1]),
dateIntervals = getDateInterval(dateFrom, dateTo);

url.searchParams.set('dateFrom', dateFrom);
url.searchParams.set('dateTo', dateTo);
window.history.replaceState({}, '', url);

$('.table.table_ap').remove();

getExperimentStats(
experimentId,
dateIntervals,
dateFrom,
dateTo,
backgroundBranchColors
backgroundBranchColors,
userId
)

load = 0;
Expand All @@ -796,6 +850,10 @@ $(document).ready(function () {
dateIntervals = getDateInterval(dateFrom, dateTo),
tag = event.currentTarget.innerText;

url.searchParams.set('dateFrom', dateFrom);
url.searchParams.set('dateTo', dateTo);
window.history.replaceState({}, '', url);

$('.table.table_ap').remove();

getExperimentStats(
Expand All @@ -804,6 +862,7 @@ $(document).ready(function () {
dateFrom,
dateTo,
backgroundBranchColors,
userId,
tag
)
})
Expand Down