Hey there, fellow developer! Ready to dive into the world of Hotjar API integration? You're in for a treat. We'll be using the detain/myadmin-hotjar-analytics
package to make our lives easier. Buckle up, and let's get started!
Before we jump in, make sure you've got:
Let's kick things off by installing our package. Fire up your terminal and run:
composer require detain/myadmin-hotjar-analytics
Easy peasy, right?
Now, let's set up those API credentials and get our Hotjar client ready to roll.
use \Detain\MyAdminHotjar\HotjarApi; $api = new HotjarApi('YOUR_API_KEY');
Replace 'YOUR_API_KEY'
with your actual Hotjar API key, and you're good to go!
Time to get our hands dirty with some basic operations.
$siteId = 123456; // Replace with your site ID $siteData = $api->getSite($siteId);
$heatmaps = $api->getHeatmaps($siteId);
$recordings = $api->getRecordings($siteId);
Ready to level up? Let's explore some advanced features.
$filteredHeatmaps = $api->getHeatmaps($siteId, [ 'date_from' => '2023-01-01', 'date_to' => '2023-12-31', 'sort' => 'created_desc' ]);
$page = 1; $limit = 20; do { $recordings = $api->getRecordings($siteId, ['page' => $page, 'limit' => $limit]); // Process recordings $page++; } while (count($recordings) == $limit);
try { $data = $api->getSomeData(); } catch (\Exception $e) { error_log('Hotjar API Error: ' . $e->getMessage()); }
Let's put it all together with a practical example – displaying heatmap data on a dashboard.
function displayHeatmapDashboard($siteId) { $api = new HotjarApi('YOUR_API_KEY'); $heatmaps = $api->getHeatmaps($siteId, ['sort' => 'created_desc', 'limit' => 5]); echo "<h2>Latest Heatmaps</h2>"; echo "<ul>"; foreach ($heatmaps as $heatmap) { echo "<li>{$heatmap['name']} - Created on: {$heatmap['created_at']}</li>"; } echo "</ul>"; }
Running into issues? Here are some common pitfalls:
And there you have it! You're now equipped to integrate Hotjar's powerful analytics into your PHP projects. Remember, the detain/myadmin-hotjar-analytics
package documentation is your friend for more advanced use cases.
Now go forth and analyze those heatmaps like a boss! Happy coding! 🚀