{"id":150756,"date":"2025-03-23T01:24:15","date_gmt":"2025-03-23T01:24:15","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/leverage-usebeacon-and-beforeunload-in-google-analytics\/"},"modified":"2025-03-23T01:24:15","modified_gmt":"2025-03-23T01:24:15","slug":"leverage-usebeacon-and-beforeunload-in-google-analytics","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=150756","title":{"rendered":"Leverage useBeacon And beforeunload In Google Analytics"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>This nifty little solution will let you calculate the time spent on pages that are not tracked in Google Analytics by default. These include both bounced landing pages and exit pages. Bounced pages and exit pages lack the necessary subsequent pageview, which Google Analytics uses to calculate time-based metrics.<\/p>\n<p>Before you go on, read this excellent article by <a href=\"https:\/\/www.twitter.com\/analyticsninja\">Yehoshua Coren<\/a>:<\/p>\n<p><a href=\"http:\/\/www.analytics-ninja.com\/blog\/2015\/02\/real-time-page-google-analytics.html\">REAL Time On Page in Google Analytics<\/a><\/p>\n<p>Yehoshua gives a very nice use case for the technical solution I\u2019m about to explore. He also leverages the <a href=\"https:\/\/www.simoahava.com\/analytics\/use-page-visibility-api-google-tag-manager\/\">Page Visibility API<\/a> to get an even more accurate overview of visitors who actually digest content, and how much of that time that content is visible on their screens. Fundamental stuff, read it!<\/p>\n<p>So what we\u2019re actually doing here is this:<\/p>\n<ol>\n<li>\n<p>On each page, use the default <strong>gtm.start<\/strong> Data Layer Variable to calculate the time when the document has started loading<\/p>\n<\/li>\n<li>\n<p>When the user decides to leave the page, either by closing the browser or navigating to another page, first calculate the time when the <em><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Events\/beforeunload\">beforeunload<\/a><\/em> event is dispatched. Then, use the <code>sendBeacon()<\/code> <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/navigator.sendBeacon\">API<\/a> to send a User Timing hit to Google Analytics without having to worry about the unload process cutting the request short.<\/p>\n<\/li>\n<\/ol>\n<p>Hopefully, you\u2019ll end up with data like this:<\/p>\n<div style=\"aspect-ratio: 798 \/ 383;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/user-timings-bounced-sessions.jpg\" title=\"User Timings for Bounced Sessions\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"383\" width=\"798\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/user-timings-bounced-sessions.jpg#ZgotmplZ\" alt=\"User Timings for Bounced Sessions\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Here you can see the User Timings recorded for pageviews of bounced sessions.<\/p>\n<p>Here\u2019s another report:<\/p>\n<div style=\"aspect-ratio: 798 \/ 541;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/exit-page-time.jpg\" title=\"Exit Page Time\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"541\" width=\"798\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/exit-page-time.jpg#ZgotmplZ\" alt=\"Exit Page Time\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>In this report, you can view Exit Pages with the time spent on each page as a secondary dimension.<\/p>\n<p>Naturally, this data would be far more useful when extracted out of the GA interface into a spreadsheet, where you can actually make calculations with the Custom Dimension values, for example. Hopefully, at some point, we\u2019ll have the possibility to calculate our own Custom Metrics, at which point it will make more sense to send this information as a metric instead. Also, read Yehoshua\u2019s article I linked to in the beginning of the post. He uses Custom Metrics, which makes actually a lot more sense if you want to extract the data.<\/p>\n<p>Nevertheless, until such a time that we can calculate on metrics, this is a useful method for obtaining a more accurate time on page across your sessions (so also for bounces and exit pages).<\/p>\n<p>To get it working, you\u2019ll need the following components:<\/p>\n<ol>\n<li>\n<p><strong>New Custom Dimension<\/strong>, session-scoped, to capture this information in GA<\/p>\n<\/li>\n<li>\n<p><strong>Data Layer Variable<\/strong> to capture the value for <strong>gtm.start<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>Data Layer Variable<\/strong> to store the time on page<\/p>\n<\/li>\n<li>\n<p><strong>Custom HTML Tag<\/strong>, which sets the <em>beforeunload<\/em> listener and does the <code>dataLayer.push()<\/code> when the page unload begins.<\/p>\n<\/li>\n<li>\n<p><strong>Timing Tag<\/strong> which uses the quite new <strong>useBeacon<\/strong> field available in Universal Analytics. This field is basically a helper for setting up the <code>sendBeacon()<\/code> request.<\/p>\n<\/li>\n<\/ol>\n<h3 id=\"1-custom-dimension\">1. Custom Dimension<\/h3>\n<p>Let\u2019s start with the Custom Dimension. We\u2019re using a session-scoped Custom Dimension for one simple reason: it will always have the last value sent during the session. This means that since we\u2019re sending the custom time on page on every single pageview, the session-scoped Custom Dimension should always have the exit page time for the session! Once we have this in place, we can add the custom dimension as a secondary dimension in the Exit Page report, giving us the dwell time for exit pages only.<\/p>\n<p>Note that the session-scoped Custom Dimension fails if the user is inactive long enough for the session to expire (30 minutes by default). So it might actually be a good idea to modify the timing script to only allow values up to 1800000 milliseconds (30 minutes).<\/p>\n<div style=\"aspect-ratio: 359 \/ 293;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/exit-page-custom-dimension.jpg\" title=\"Custom Dimension for exit page time\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"293\" width=\"359\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/exit-page-custom-dimension.jpg#ZgotmplZ\" alt=\"Custom Dimension for exit page time\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Make note of the index the new Custom Dimension gets. This is important when you\u2019re setting up the Event Tag.<\/p>\n<h3 id=\"2-data-layer-variable-for-gtmstart\">2. Data Layer Variable for gtm.start<\/h3>\n<p>The next step is to create the Data Layer Variable for <strong>gtm.start<\/strong>. You might wonder what this \u201cgtm.start\u201d is, but it\u2019s actually a property in the very first <code>dataLayer<\/code> object pushed into the Array by GTM, when the container snippet starts loading:<\/p>\n<div style=\"aspect-ratio: 490 \/ 241;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/gtm-start-datalayer.jpg\" title=\"gtm.start in datalayer\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"241\" width=\"490\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/gtm-start-datalayer.jpg#ZgotmplZ\" alt=\"gtm.start in datalayer\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>The value for this variable is a timestamp in milliseconds of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Unix_time\">Epoch time<\/a>. You don\u2019t have to worry about what this means, since all we\u2019re going to use this for is to calculate the difference between page unload time and <strong>gtm.start<\/strong> to get an approximation of how long the user spent on the page.<br \/>\nThe Data Layer Variable would look like this:<\/p>\n<div style=\"aspect-ratio: 456 \/ 551;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/dlv-gtm-start.jpg\" title=\"Data Layer Variable gtm.start\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"551\" width=\"456\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/dlv-gtm-start.jpg#ZgotmplZ\" alt=\"Data Layer Variable gtm.start\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<h3 id=\"3-data-layer-variable-for-timeonpage\">3. Data Layer Variable for timeonpage<\/h3>\n<p>You\u2019ll also need to create a Data Layer Variable for <strong>timeonpage<\/strong>, which is where we\u2019ll store the time on page, pushed in the <em>beforeunload<\/em> callback. So create another Data Layer Variable that looks like this:<\/p>\n<div style=\"aspect-ratio: 444 \/ 553;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/dlv-time-on-page.jpg\" title=\"Data Layer Variable timeonpage\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"553\" width=\"444\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/dlv-time-on-page.jpg#ZgotmplZ\" alt=\"Data Layer Variable timeonpage\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<h3 id=\"4-custom-html-tag\">4. Custom HTML Tag<\/h3>\n<p>The next step is our custom <em>beforeunload<\/em> listener. Create a new Custom HTML Tag, and set it to fire with the <strong>All Pages<\/strong> Trigger. Add the following code within:<\/p>\n<div class=\"highlight\">\n<pre style=\"background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4\"><code class=\"language-html\" data-lang=\"html\">script&gt;\n  <span style=\"color:#0aa\">window<\/span>.addEventListener(<span style=\"color:#a50\">'beforeunload'<\/span>, <span style=\"color:#00a\">function<\/span>() {\n    <span style=\"color:#0aa\">window<\/span>.dataLayer.push({\n      <span style=\"color:#a50\">'event'<\/span> : <span style=\"color:#a50\">'unloadEvent'<\/span>,\n      <span style=\"color:#a50\">'timeonpage'<\/span> : <span style=\"color:#00a\">new<\/span> <span style=\"color:#0aa\">Date<\/span>().getTime() - {{DLV - gtm.start}}\n    });\n  });\n<span style=\"color:#1e90ff;font-weight:bold\">script<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p>This attaches the <em>beforeunload<\/em> listener to the global <code>window<\/code> object. When the unload process begins, i.e. when the user chooses to leave the page, the callback is invoked, and a <code>dataLayer.push()<\/code> is executed, with a custom \u2018event\u2019 value and also a value for the \u2018timeonpage\u2019 Variable we just created.<\/p>\n<p>The time on page is calculated by getting the timestamp for the <em>beforeunload<\/em> event, and subtracting the <strong>gtm.start<\/strong> timestamp from it. The result is the time in milliseconds between these two events. If you want to have a safeguard for session expiration, cap this time at 1800000 milliseconds, which is 30 minutes.<\/p>\n<p>Now all we need is the Timing Tag, which sends the <strong>timeonpage<\/strong> value both as a Timing value and as a Custom Dimension value.<\/p>\n<h3 id=\"5-user-timing-tag\">5. User Timing Tag<\/h3>\n<p><em>User Timing<\/em> is a hit type that you can use to send your own timing events to Google Analytics. A common use case is to measure the <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/user-timings#booya\">load time of linked assets<\/a>, such as huge, bloated JavaScript libraries (I\u2019m looking at you, non-minified jQuery!).<\/p>\n<p>But you can use User Timings for anything on the site that can be measured in milliseconds. So it works perfectly with page load time as well.<\/p>\n<p>Before you create the Tag, you\u2019ll need the Trigger that makes the Tag fire. The Trigger is simply a Custom Event Trigger, that fires with event name <strong>unloadEvent<\/strong>:<\/p>\n<div style=\"aspect-ratio: 548 \/ 489;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/trigger-unloadevent.jpg\" title=\"Trigger for unloadEvent\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"489\" width=\"548\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/trigger-unloadevent.jpg#ZgotmplZ\" alt=\"Trigger for unloadEvent\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Next, create a new Google Analytics \/ Universal Analytics Tag, attach the Trigger you just created to it, and set the Tag fields to look something like this:<\/p>\n<div style=\"aspect-ratio: 596 \/ 916;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/timing-tag.jpg\" title=\"User Timing Tag\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"916\" width=\"596\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/timing-tag.jpg#ZgotmplZ\" alt=\"User Timing Tag\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>If you were to save this now and publish your container, the solution would be very unreliable. This is because the <em>beforeunload<\/em> event signals the browser to start the unload process, and the unload process is <strong>brutal<\/strong>. Any threads that are running once the browser reaches the <em>unload<\/em> stage are cut off, and all requests are cancelled. This is because the browser doesn\u2019t want to let anything impede the user\u2019s desire to leave the page.<\/p>\n<p>Perfectly understandable.<\/p>\n<p>It is for this reason that we\u2019ll leverage yet another little-known API: <code>navigator.sendBeacon()<\/code>. This API turns any request made in its scope into an asynchronous, uninterruptible call to whatever endpoint you choose. So, even if the browser window closes or you navigate from the site, the request is allowed to complete before the browser instance is unloaded from memory.<\/p>\n<p>Google Analytics were quick to react to this API, and they published their own shorthand for it: <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#useBeacon\">the <em>useBeacon<\/em> field<\/a>. Read <a href=\"https:\/\/www.twitter.com\/thyng\">David Vallejo<\/a>\u2019s <a href=\"https:\/\/www.thyngster.com\/google-analytics-added-sendbeacon-functionality-universal-analytics-javascript-api\/\">nice review<\/a> about this new feature to get acquainted.<\/p>\n<p>!!! <strong>UPDATE<\/strong> !!!<br \/>\nThe <code>useBeacon<\/code> has been deprecated. Use the <code>transport<\/code> field name instead, and set its value to <code>beacon<\/code>. Read about the field <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#transport\">here<\/a>.<\/p>\n<p>Anyway, <strong>useBeacon<\/strong> turns the call into a POST request (instead of the usual GET), and passes it asynchronously to the GA endpoint using <code>navigator.sendBeacon()<\/code>.<\/p>\n<p>To add this feature to the User Timing Tag, add <strong>useBeacon<\/strong> as a <em>Field To Set<\/em>, and set its value to <strong>true<\/strong>.<\/p>\n<p>Also, add the <strong>{{DLV &#8211; timeonpage}}<\/strong> as a Custom Dimension, using the index number you got from Step 1.<\/p>\n<p>So now the More Settings of your User Timing Tag should look like this:<\/p>\n<div style=\"aspect-ratio: 798 \/ 345;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2015\/02\/fields-to-set-timing.jpg\" title=\"Fields To Set User Timing\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"345\" width=\"798\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2015\/02\/fields-to-set-timing.jpg#ZgotmplZ\" alt=\"Fields To Set User Timing\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Save the Tag, Preview &amp; Debug the Tag, and Publish when you\u2019re ready.<\/p>\n<p>Then read the caveats below. Or actually, it would be good if you read these before you publish.<\/p>\n<p>                <span class=\"simmer\"><br \/>\n  <span class=\"close\">X<\/span><\/p>\n<p>\n    <span class=\"fa fa-md fa-bell\"\/><br \/>\n    <strong>The Simmer Newsletter<\/strong>\n  <\/p>\n<p>\n    Subscribe to the <a href=\"https:\/\/www.simoahava.com\/newsletter\/\">Simmer newsletter<\/a> to get the latest news and content from Simo Ahava into your email inbox!\n  <\/p>\n<p>  <\/span><\/p>\n<h2 id=\"caveats\">Caveats<\/h2>\n<p>There is actually only one major caveat here. <code>navigator.sendBeacon()<\/code> has <strong>horrible<\/strong> browser support. Like, dismal. Basically, Internet Explorer and Safari do not support it all. This is a big setback, as IE is one of the most popular desktop browsers, and Safari is among the most popular mobile browsers.<\/p>\n<p>The thing is, you don\u2019t really have to write any fallback functions for browsers that don\u2019t support the API. The Universal Analytics library detects if <code>navigator.sendBeacon()<\/code> is supported, and if it isn\u2019t, the hit is sent normally.<\/p>\n<p>Depending on your site, there\u2019s still a good chance that the hit gets sent. This depends on how long it takes for the browser to unload your site.<\/p>\n<p>If you want to play it safer, you could write your own click handler that intercepts external links, fires the Timing Tag, and only then lets the link redirect proceed. This would cover exits from your site to other sites nicely, but it wouldn\u2019t help with the most interesting use case of people closing browser windows and tabs.<\/p>\n<p>This is a problem we\u2019ll just have to live with. However, as an eternal optimist, I see this as a solution that <strong>can only get better with time<\/strong>. Once <code>navigator.sendBeacon()<\/code> gets better support and once we get calculated Custom Metrics, this solution will be so awesome.<\/p>\n<p>Right now it\u2019s more of a prototype, but as Yehoshua shows you, it can already have very interesting analytics applications.<\/p>\n<p>Well, I\u2019d be remiss if I didn\u2019t mention one other, small caveat. Triggering code on <em>beforeunload<\/em> invalidates the back-forward cache (<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Working_with_BFCache\">BFCache<\/a>) in Firefox. This means that the page state of the page is no longer cached, and if you\u2019re trusting e.g. form field values to this cache, you\u2019ll need to make adjustments.<\/p>\n<h2 id=\"summary\">Summary<\/h2>\n<p>In this quite simple solution we\u2019re leveraging some pretty cool APIs again. The point is partly to give you a tool to get better data out of Google Analytics, but at the same time we\u2019re doing what I love best: using JavaScript and Google Tag Manager to get data from unexpected places.<\/p>\n<p>As I say in the previous chapter, this solution will only get better with time.<\/p>\n<p>Hopefully, once <code>navigator.sendBeacon()<\/code> get better browser support, it will become the default request mechanism for all Google Analytics hits. It just makes so much sense. Also, it means that you won\u2019t need to protect your tags with <code>setTimeout()<\/code> calls or the <strong>Wait For Tags<\/strong> method in Google Tag Manager.<\/p>\n<p>But from the look of things, this is still a long way off.<\/p>\n<\/p><\/div>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><br \/>\n<br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This nifty little solution will let you calculate the time spent on pages that are not tracked in Google Analytics by default. These include both bounced landing pages and exit pages. Bounced pages and exit pages lack the necessary subsequent pageview, which Google Analytics uses to calculate time-based metrics. Before you go on, read this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":150757,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[12765,62877,1531,11480,62876],"dealstore":[],"offerexpiration":[],"class_list":["post-150756","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-analytics","tag-beforeunload","tag-google","tag-leverage","tag-usebeacon"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Leverage useBeacon And beforeunload In Google Analytics - Som2ny Network<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fivemor.com\/?p=150756\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Leverage useBeacon And beforeunload In Google Analytics - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"This nifty little solution will let you calculate the time spent on pages that are not tracked in Google Analytics by default. These include both bounced landing pages and exit pages. Bounced pages and exit pages lack the necessary subsequent pageview, which Google Analytics uses to calculate time-based metrics. Before you go on, read this [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=150756\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-23T01:24:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"798\" \/>\n\t<meta property=\"og:image:height\" content=\"383\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=150756#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=150756\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"Leverage useBeacon And beforeunload In Google Analytics\",\"datePublished\":\"2025-03-23T01:24:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=150756\"},\"wordCount\":1816,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=150756#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg\",\"keywords\":[\"Analytics\",\"beforeunload\",\"Google\",\"Leverage\",\"useBeacon\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=150756#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=150756\",\"url\":\"https:\/\/fivemor.com\/?p=150756\",\"name\":\"Leverage useBeacon And beforeunload In Google Analytics - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=150756#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=150756#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg\",\"datePublished\":\"2025-03-23T01:24:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=150756#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=150756\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=150756#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg\",\"width\":798,\"height\":383},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=150756#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Leverage useBeacon And beforeunload In Google Analytics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/fivemor.com\/#website\",\"url\":\"https:\/\/fivemor.com\/\",\"name\":\"Som2ny Network\",\"description\":\"Daily Deals\",\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/fivemor.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/fivemor.com\/#organization\",\"name\":\"Som2ny Network\",\"url\":\"https:\/\/fivemor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png\",\"width\":300,\"height\":86,\"caption\":\"Som2ny Network\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/fivemor.com\"],\"url\":\"https:\/\/fivemor.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Leverage useBeacon And beforeunload In Google Analytics - Som2ny Network","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fivemor.com\/?p=150756","og_locale":"en_US","og_type":"article","og_title":"Leverage useBeacon And beforeunload In Google Analytics - Som2ny Network","og_description":"This nifty little solution will let you calculate the time spent on pages that are not tracked in Google Analytics by default. These include both bounced landing pages and exit pages. Bounced pages and exit pages lack the necessary subsequent pageview, which Google Analytics uses to calculate time-based metrics. Before you go on, read this [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=150756","og_site_name":"Som2ny Network","article_published_time":"2025-03-23T01:24:15+00:00","og_image":[{"width":798,"height":383,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=150756#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=150756"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"Leverage useBeacon And beforeunload In Google Analytics","datePublished":"2025-03-23T01:24:15+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=150756"},"wordCount":1816,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=150756#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg","keywords":["Analytics","beforeunload","Google","Leverage","useBeacon"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=150756#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=150756","url":"https:\/\/fivemor.com\/?p=150756","name":"Leverage useBeacon And beforeunload In Google Analytics - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=150756#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=150756#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg","datePublished":"2025-03-23T01:24:15+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=150756#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=150756"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=150756#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/03\/user-timings-bounced-sessions.jpg","width":798,"height":383},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=150756#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"Leverage useBeacon And beforeunload In Google Analytics"}]},{"@type":"WebSite","@id":"https:\/\/fivemor.com\/#website","url":"https:\/\/fivemor.com\/","name":"Som2ny Network","description":"Daily Deals","publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fivemor.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fivemor.com\/#organization","name":"Som2ny Network","url":"https:\/\/fivemor.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2026\/07\/4a0953c4-logo-300x86-1.png","width":300,"height":86,"caption":"Som2ny Network"},"image":{"@id":"https:\/\/fivemor.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/729ae85bf62b9917e93538db2f2688ca?s=96&r=g&default=https%3A%2F%2Ffivemor.com%2Fwp-content%2Fplugins%2Fbuddypress-first-letter-avatar%2Fimages%2Fdefault%2F96%2Flatin_a.png","caption":"admin"},"sameAs":["https:\/\/fivemor.com"],"url":"https:\/\/fivemor.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/150756","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=150756"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/150756\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/150757"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150756"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=150756"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=150756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}