Skip to content

Commit

Permalink
add google analytics support
Browse files Browse the repository at this point in the history
  • Loading branch information
saleem-hadad committed Sep 4, 2018
1 parent 96cc74d commit aacef69
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion publishable/config/larecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
*/

'settings' => [
'auth' => false
'auth' => false,
'ga_id' => ''
],

/*
Expand Down
13 changes: 13 additions & 0 deletions resources/views/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,18 @@
<script type="text/javascript" src="{{ asset($js) }}"></script>
@endforeach
@endif

{{-- Google Analytics --}}
@if(config('larecipe.settings.ga_id'))
<script async src="https://www.googletagmanager.com/gtag/js?id={{ config('larecipe.settings.ga_id') }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', "{{ config('larecipe.settings.ga_id') }}");
</script>
@endif
{{-- /Google Analytics --}}
</body>
</html>
13 changes: 13 additions & 0 deletions tests/Feature/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ public function back_to_top_button_is_visible_only_if_enabled()
Config::set('larecipe.ui.back_to_top', true);
$this->get('/docs/1.0')->assertSee('<larecipe-back-to-top></larecipe-back-to-top>');
}

/** @test */
public function ga_script_is_visible_only_if_ga_id_is_set()
{
Config::set('larecipe.settings.ga_id', '');
$this->get('/docs/1.0')
->assertDontSee('googletagmanager');

Config::set('larecipe.settings.ga_id', 'ga_code_id');
$this->get('/docs/1.0')
->assertSee('googletagmanager')
->assertSee('ga_code_id');
}
}

0 comments on commit aacef69

Please sign in to comment.