Trackthemetric + Laravel
Here's how you can set up Trackthemetric analytics in a Laravel project.
1Add the script to your Blade layout
1. To ensure the tracking code runs across your site, place it inside your main Blade layout (e.g. resources/views/layouts/app.blade.php).
2. Add the following script into the <head> section:
<!DOCTYPE html>
<html lang="en">
<head>
<script
defer
id="TrackTheMetric"
data-website-id="{{ config('trackthemetric.website_id') }}"
data-domain="{{ config('trackthemetric.domain') }}"
src="https://app.trackthemetric.com/tracker.js"
></script>
</head>
<body>
@yield('content')
</body>
</html>
2Configure environment variables
1. Instead of hardcoding your IDs, store them in your .envfile:
TRACKTHEMETRIC_WEBSITE_ID=your_website_id_here TRACKTHEMETRIC_DOMAIN=yourdomain.com
2. Then, create a config file to load them in : config/trackthemetric.php:
<?php
return [
'website_id' => env('TRACKTHEMETRIC_WEBSITE_ID'),
'domain' => env('TRACKTHEMETRIC_DOMAIN'),
];
3Verifying the setup
Once you've deployed your project:
- Open your production site in the browser.
- Head over to your Trackthemetric dashboard.
- Within a few minutes, you should see traffic starting to appear.