{"id":169746,"date":"2025-04-03T20:37:17","date_gmt":"2025-04-03T20:37:17","guid":{"rendered":"https:\/\/peraltafinancing.com\/analytics\/send-mail-upon-google-tag-manager-event\/"},"modified":"2025-04-03T20:37:17","modified_gmt":"2025-04-03T20:37:17","slug":"send-mail-upon-google-tag-manager-event","status":"publish","type":"post","link":"https:\/\/fivemor.com\/?p=169746","title":{"rendered":"Send Mail Upon Google Tag Manager Event"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p>Let\u2019s say you want to set up a rudimentary email alert system in your <a href=\"https:\/\/www.google.com\/tagmanager\">Google Tag Manager<\/a> implementation. Say, for example, you want to receive an email every time an uncaught error occurs on your website. It\u2019s not a very good use case, since a large website can spawn hundreds of uncaught exceptions in a short period of time, but let\u2019s just pretend for now.<\/p>\n<p>If you know your JavaScript, you\u2019ll know that you can\u2019t send mail using client-side code. That\u2019s a browser security thing, and I completely understand it. However, a vast majority of websites are created using a CMS which might provide some mail function or hook for you to use. And even if you don\u2019t have a cooperative web server (or there\u2019s no way you can persuade your developers to help), you could use any one of the <a href=\"http:\/\/www.programmableweb.com\/apis\/directory\/1?apicat=email\">online email APIs<\/a> that are out there.<\/p>\n<p>In this post, I\u2019ll show two easy ways of getting your mail sent: using the <strong>mail()<\/strong> function in PHP, and using <a href=\"http:\/\/www.mandrill.com\">Mandrill<\/a>\u2019s API. My use case will be simple: every time an uncaught exception occurs on the website, an email is sent to my address with details about the error. I\u2019ll be using the <a href=\"https:\/\/support.google.com\/tagmanager\/answer\/3415369?hl=en#JSErrorListener\">JavaScript Error Listener<\/a> to catch the error and push it into the mailer.<\/p>\n<p><strong>Word of warning<\/strong>: The examples in this post are very rudimentary and serve simply to show you what the basics are of sending your emails using GTM. Before you start coding a mailer system of your own, make sure you familiarize yourself with the documentation so that you don\u2019t accidentally or unintentionally open a door for mail spammers.<\/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=\"before-you-start\">Before you start<\/h2>\n<p>For this to work, you\u2019ll need the GTM JavaScript Error Listener up and running, with a couple of macros ready to collect data on the uncaught errors.<\/p>\n<p>So first, set up the error listener with a firing rule of your choice. I have it running on all pages, but if you want to monitor just a specific page, feel free to change the rule.<\/p>\n<div style=\"aspect-ratio: 646 \/ 366;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/04\/error-listener.jpg\" title=\"JavaScript Error Listener\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"366\" width=\"646\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/04\/error-listener.jpg#ZgotmplZ\" alt=\"JavaScript Error Listener\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>Next, you\u2019ll need three macros: one for the error message, one for the faulty URL, and one for the line number where the faulty code was found.<\/p>\n<p>{{Error &#8211; MSG}}<br \/>Macro Type: Data Layer Variable<br \/>Data Layer Variable Name: gtm.errorMessage<\/p>\n<p>{{Error &#8211; URL}}<br \/>Macro Type: Data Layer Variable<br \/>Data Layer Variable Name: gtm.errorUrl<\/p>\n<p>(<strong>NOTE<\/strong>: At the time of writing, this macro will return an empty string. However, I\u2019m sure it will be fixed soon. Until then, you can use the default {{url}} macro instead.)<\/p>\n<p>{{Error &#8211; LINE}}<br \/>Macro Type: Data Layer Variable<br \/>Data Layer Variable Name: gtm.errorLineNumber<\/p>\n<div style=\"aspect-ratio: 610 \/ 255;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/04\/error-macros.jpg\" title=\"Error Listener Macros\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"255\" width=\"610\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/04\/error-macros.jpg#ZgotmplZ\" alt=\"Error Listener Macros\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>And then you\u2019re good to go.<\/p>\n<h2 id=\"send-mail-with-php\">Send mail with PHP<\/h2>\n<p>If your site has been built with PHP, you can use the built-in <strong><a href=\"https:\/\/www.w3schools.com\/php\/func_mail_mail.asp\">mail()<\/a><\/strong> function to send your emails. (If your site runs on WordPress, you should also take a look at the <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/wp_mail\">wp_mail()<\/a> function which is a bit more robust!)<\/p>\n<p>For this method to work, you\u2019ll need two things:<\/p>\n<ol>\n<li>\n<p>A Custom HTML Tag in your GTM setup to send the data payload to the PHP script<\/p>\n<\/li>\n<li>\n<p>A PHP script which processes the data and sends it<\/p>\n<\/li>\n<\/ol>\n<p>The Custom HTML Tag below uses <a href=\"http:\/\/www.jquery.com\">jQuery<\/a> to send the POST request, so you\u2019ll need to make sure that jQuery is loaded <strong>before<\/strong> the Custom HTML is run. I\u2019m not a huge fan of jQuery or really any JS framework stacked on top of GTM, but for making POST requests using AJAX, it\u2019s a huge help.<\/p>\n<p>So anyway, here\u2019s what the Custom HTML Tag looks like:<\/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:#00a\">var<\/span> data = {\n    errorUrl: {{<span style=\"color:#0aa\">Error<\/span> - URL}},\n    errorLine: {{<span style=\"color:#0aa\">Error<\/span> - LINE}},\n    errorMsg: {{<span style=\"color:#0aa\">Error<\/span> - MSG}}\n  };\n  jQuery.ajax({\n    type: <span style=\"color:#a50\">\"POST\"<\/span>,\n    url: <span style=\"color:#a50\">\"\/wp-content\/uploads\/email.php\"<\/span>,\n    data: data\n  });\n<span style=\"color:#1e90ff;font-weight:bold\">script<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p>Like I said, it\u2019s really bare-bones. You should add some validation code, maybe utilize the <em>success<\/em>, <em>error<\/em> and <em>complete<\/em> callbacks and so forth.<\/p>\n<p>The first bit is about building the payload. I\u2019m doing that by creating an object literal, which is populated by the values retrieved by the error macros created earlier. So when an error occurs, the object <strong>data<\/strong> might have the following key-value pairs:<\/p>\n<p>errorUrl: <code>https:\/\/www.simoahava.com\/<\/code><br \/>errorLine: \u201c3\u201d<br \/>errorMsg: \u201cUncaught ReferenceError: myFunction is not defined\u201d<\/p>\n<p>The next bit is about using jQuery\u2019s ajax() function to send the data with a POST request to the custom PHP script. You\u2019ll need to specify the location of the script for this to work.<\/p>\n<p>I wrote a <em>very<\/em> simple mail script, which you can find below. Save this as <strong>email.php<\/strong> and store it in a location you can refer to in the POST request.<\/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-php\" data-lang=\"php\"><span style=\"color:#4c8317\"><?php <\/span?>\n<span style=\"color:#00a\">if<\/span>(<span style=\"color:#a00\">$_POST<\/span>){\n  <span style=\"color:#a00\">$message<\/span> = <span style=\"color:#a50\">'Uncaught exception on page '<\/span> . <span style=\"color:#a00\">$_POST<\/span>[<span style=\"color:#a50\">'errorUrl'<\/span>] . \n             <span style=\"color:#a50\">', line '<\/span> . <span style=\"color:#a00\">$_POST<\/span>[<span style=\"color:#a50\">'errorLine'<\/span>] . \n             <span style=\"color:#a50\">': '<\/span> . <span style=\"color:#a00\">$_POST<\/span>[<span style=\"color:#a50\">'errorMsg'<\/span>];\n  mail(<span style=\"color:#a50\">\"<a href=\"https:\/\/www.simoahava.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"6b3332312b33323145080406\">[email\u00a0protected]<\/a>\"<\/span>, <span style=\"color:#a50\">\"[GTM simoahava.com] Uncaught error\"<\/span>, <span style=\"color:#a00\">$message<\/span>);\n}\n<span style=\"color:#4c8317\">?&gt;<\/span>\n<\/span><\/code><\/pre>\n<\/div>\n<p>Again, very simple. The PHP basically waits for a POST request, after which it populates a variable $message with the payload data. Next, it utilizes the mail() function to send mail to my email with the subject <code>[GTM simoahava.com] Uncaught error<\/code>, and the error data in the message body.<\/p>\n<p>Ta-da! You\u2019ve just created your email alert system using some simple jQuery and PHP. Here\u2019s what a sample email looks like:<\/p>\n<div style=\"aspect-ratio: 748 \/ 302;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/04\/error-mail.jpg\" title=\"Error mail\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"302\" width=\"748\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/04\/error-mail.jpg#ZgotmplZ\" alt=\"Error mail\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<h2 id=\"send-mail-with-the-mandrill-api\">Send mail with the Mandrill API<\/h2>\n<p>Mandrill is an online mailing system, which provides a pretty flexible framework for sending mail using their JSON API. I chose it simply because it\u2019s free (you have to pay if you send more than 12,000 mails per month using Mandrill), and because it looks pretty simple to set up.<\/p>\n<p>To get things up and running, you\u2019ll need two things:<\/p>\n<ol>\n<li>\n<p>Mandrill API key<\/p>\n<\/li>\n<li>\n<p>A Custom HTML Tag to send the payload data to the API<\/p>\n<\/li>\n<\/ol>\n<p>To get the API key, browse to <a href=\"http:\/\/mandrill.com\/signup\/\">http:\/\/mandrill.com\/signup\/<\/a>, and sign up for access. Once you log in for the first time, you should click on the \u201cGet API Keys\u201d button.<\/p>\n<div style=\"aspect-ratio: 782 \/ 361;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/04\/mandrill-get-keys.jpg\" title=\"Mandrill get API keys\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"361\" width=\"782\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/04\/mandrill-get-keys.jpg#ZgotmplZ\" alt=\"Mandrill get API keys\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>In the next screen, choose the \u201c+ New API Key\u201d to generate a new API key for you. You should immediately see your newly generated key in the list below.<\/p>\n<div style=\"aspect-ratio: 290 \/ 276;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/04\/new-api-key.jpg\" title=\"New API Key\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"276\" width=\"290\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/04\/new-api-key.jpg#ZgotmplZ\" alt=\"New API Key\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<p>And that\u2019s it for setting up your Mandrill account. What you need to do next is create the Custom HTML Tag which negotiates with the Mandrill API to send your mail. Here\u2019s what this tag should look like:<\/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:#00a\">var<\/span> data = {\n    <span style=\"color:#a50\">\"key\"<\/span>: <span style=\"color:#a50\">\"IVrVuUMfhLFbY97Rjjp1ug\"<\/span>,\n    <span style=\"color:#a50\">\"message\"<\/span>: {\n      <span style=\"color:#a50\">\"text\"<\/span>: <span style=\"color:#a50\">\"Uncaught exception on page \"<\/span> + {{<span style=\"color:#0aa\">Error<\/span> - URL}} +\n            <span style=\"color:#a50\">\", line \"<\/span> + {{<span style=\"color:#0aa\">Error<\/span> - LINE}} +\n            <span style=\"color:#a50\">\": \"<\/span> + {{<span style=\"color:#0aa\">Error<\/span> - MSG}},\n      <span style=\"color:#a50\">\"subject\"<\/span>: <span style=\"color:#a50\">\"[GTM simoahava.com] Uncaught error\"<\/span>,\n      <span style=\"color:#a50\">\"from_email\"<\/span>: <span style=\"color:#a50\">\"<a href=\"https:\/\/www.simoahava.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"36455f5b5976455f5b59575e5740571855595b\">[email\u00a0protected]<\/a>\"<\/span>OB,\n      <span style=\"color:#a50\">\"from_name\"<\/span>: <span style=\"color:#a50\">\"GTM Simo\"<\/span>,\n      <span style=\"color:#a50\">\"to\"<\/span>: [\n        {\n          <span style=\"color:#a50\">\"email\"<\/span>: <span style=\"color:#a50\">\"<a href=\"https:\/\/www.simoahava.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"94e7fdf9fbd4e7fdf9fbf5fcf5e2f5baf7fbf9\">[email\u00a0protected]<\/a>\"<\/span>,\n          <span style=\"color:#a50\">\"name\"<\/span>: <span style=\"color:#a50\">\"Simo Ahava\"<\/span>,\n          <span style=\"color:#a50\">\"type\"<\/span>: <span style=\"color:#a50\">\"to\"<\/span>\n        }\n      ]\n    },\n    <span style=\"color:#a50\">\"async\"<\/span>: <span style=\"color:#00a\">true<\/span>\n  };\n  jQuery.ajax({\n    type: <span style=\"color:#a50\">\"POST\"<\/span>,\n    url: <span style=\"color:#a50\">\"https:\/\/mandrillapp.com\/api\/1.0\/messages\/send.json\"<\/span>,\n    dataType: <span style=\"color:#a50\">\"json\"<\/span>,\n    data: data\n  });\n<span style=\"color:#1e90ff;font-weight:bold\">script<\/span>&gt;<\/code><\/pre>\n<\/div>\n<p>As you can see, you need to add a bit more information into the payload object to satisfy the <a href=\"https:\/\/mandrillapp.com\/api\/docs\/messages.JSON.html#method=send\">requirements of the Mandrill API<\/a>.<\/p>\n<p>The code itself is pretty similar to when we sent the POST request to the PHP script, with the notable exception of having to declare the dataType parameter explicitly as \u201cjson\u201d.<\/p>\n<p>When the mail is sent successfully, you should again see a pretty hideous email in your inbox. By the way, take a look at Mandrill\u2019s reports. You\u2019ll see some pretty interesting data on your API use, so if you want to build this into a whole email-system-thing, you can use Mandrill\u2019s powerful features to diagnose your mail traffic.<\/p>\n<div style=\"aspect-ratio: 1213 \/ 365;\" class=\"figure nocaption\">\n<p>    <a href=\"https:\/\/www.simoahava.com\/images\/2014\/04\/mandrill-features.jpg\" title=\"Mandrill features\"><\/p>\n<p>    <img decoding=\"async\" class=\"fig-img\" height=\"365\" width=\"1213\" loading=\"lazy\" src=\"https:\/\/www.simoahava.com\/images\/2014\/04\/mandrill-features.jpg#ZgotmplZ\" alt=\"Mandrill features\"\/><\/p>\n<p>    <\/a><\/p>\n<\/div>\n<h2 id=\"conclusions\">Conclusions<\/h2>\n<p>Sending mail via Google Tag Manager doesn\u2019t happen with just a click of a button. Because browser security prevents you from sending email directly with JavaScript (i.e. GTM), you\u2019ll need to access either server-side methods or some external API. This post provided very rudimentary examples of both scenarios.<\/p>\n<p>If you want to build on this idea, be sure to make your code as waterproof as possible. Hijacking someone\u2019s mail script is a really easy way to cause a lot of damage in the form of spam. Also, I don\u2019t like the fact that you have to provide the Mandrill API key \u201cin the open\u201d, so you might want to look at Mandrill\u2019s PHP client as a way to use Mandrill\u2019s API to send the mail server-side.<\/p>\n<p>And before you try anything, the API key I created was just for testing purposes, it no longer exists.<\/p>\n<p>Anyway, perhaps at some point GTM will support sending mail via GTM\u2019s own protocols, which will make this post nice and obsolete, but until then: have fun!<\/p>\n<\/p><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s say you want to set up a rudimentary email alert system in your Google Tag Manager implementation. Say, for example, you want to receive an email every time an uncaught error occurs on your website. It\u2019s not a very good use case, since a large website can spawn hundreds of uncaught exceptions in a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":169747,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12033],"tags":[9252,1531,15540,14495,11285,1791],"dealstore":[],"offerexpiration":[],"class_list":["post-169746","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-event","tag-google","tag-mail","tag-manager","tag-send","tag-tag"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Send Mail Upon Google Tag Manager Event - 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=169746\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Send Mail Upon Google Tag Manager Event - Som2ny Network\" \/>\n<meta property=\"og:description\" content=\"Let\u2019s say you want to set up a rudimentary email alert system in your Google Tag Manager implementation. Say, for example, you want to receive an email every time an uncaught error occurs on your website. It\u2019s not a very good use case, since a large website can spawn hundreds of uncaught exceptions in a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fivemor.com\/?p=169746\" \/>\n<meta property=\"og:site_name\" content=\"Som2ny Network\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-03T20:37:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"646\" \/>\n\t<meta property=\"og:image:height\" content=\"366\" \/>\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=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/fivemor.com\/?p=169746#article\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/?p=169746\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371\"},\"headline\":\"Send Mail Upon Google Tag Manager Event\",\"datePublished\":\"2025-04-03T20:37:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=169746\"},\"wordCount\":1338,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/fivemor.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=169746#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg\",\"keywords\":[\"event\",\"Google\",\"Mail\",\"Manager\",\"send\",\"TAG\"],\"articleSection\":[\"Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/fivemor.com\/?p=169746#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/fivemor.com\/?p=169746\",\"url\":\"https:\/\/fivemor.com\/?p=169746\",\"name\":\"Send Mail Upon Google Tag Manager Event - Som2ny Network\",\"isPartOf\":{\"@id\":\"https:\/\/fivemor.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/fivemor.com\/?p=169746#primaryimage\"},\"image\":{\"@id\":\"https:\/\/fivemor.com\/?p=169746#primaryimage\"},\"thumbnailUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg\",\"datePublished\":\"2025-04-03T20:37:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/fivemor.com\/?p=169746#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/fivemor.com\/?p=169746\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/fivemor.com\/?p=169746#primaryimage\",\"url\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg\",\"contentUrl\":\"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg\",\"width\":646,\"height\":366},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/fivemor.com\/?p=169746#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/fivemor.com\/?bp_activities=1\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Send Mail Upon Google Tag Manager Event\"}]},{\"@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":"Send Mail Upon Google Tag Manager Event - 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=169746","og_locale":"en_US","og_type":"article","og_title":"Send Mail Upon Google Tag Manager Event - Som2ny Network","og_description":"Let\u2019s say you want to set up a rudimentary email alert system in your Google Tag Manager implementation. Say, for example, you want to receive an email every time an uncaught error occurs on your website. It\u2019s not a very good use case, since a large website can spawn hundreds of uncaught exceptions in a [&hellip;]","og_url":"https:\/\/fivemor.com\/?p=169746","og_site_name":"Som2ny Network","article_published_time":"2025-04-03T20:37:17+00:00","og_image":[{"width":646,"height":366,"url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fivemor.com\/?p=169746#article","isPartOf":{"@id":"https:\/\/fivemor.com\/?p=169746"},"author":{"name":"admin","@id":"https:\/\/fivemor.com\/#\/schema\/person\/b85e3c3dc0e1daea076524dc8810c371"},"headline":"Send Mail Upon Google Tag Manager Event","datePublished":"2025-04-03T20:37:17+00:00","mainEntityOfPage":{"@id":"https:\/\/fivemor.com\/?p=169746"},"wordCount":1338,"commentCount":0,"publisher":{"@id":"https:\/\/fivemor.com\/#organization"},"image":{"@id":"https:\/\/fivemor.com\/?p=169746#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg","keywords":["event","Google","Mail","Manager","send","TAG"],"articleSection":["Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fivemor.com\/?p=169746#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fivemor.com\/?p=169746","url":"https:\/\/fivemor.com\/?p=169746","name":"Send Mail Upon Google Tag Manager Event - Som2ny Network","isPartOf":{"@id":"https:\/\/fivemor.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fivemor.com\/?p=169746#primaryimage"},"image":{"@id":"https:\/\/fivemor.com\/?p=169746#primaryimage"},"thumbnailUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg","datePublished":"2025-04-03T20:37:17+00:00","breadcrumb":{"@id":"https:\/\/fivemor.com\/?p=169746#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fivemor.com\/?p=169746"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fivemor.com\/?p=169746#primaryimage","url":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg","contentUrl":"https:\/\/fivemor.com\/wp-content\/uploads\/2025\/04\/error-listener.jpg","width":646,"height":366},{"@type":"BreadcrumbList","@id":"https:\/\/fivemor.com\/?p=169746#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fivemor.com\/?bp_activities=1"},{"@type":"ListItem","position":2,"name":"Send Mail Upon Google Tag Manager Event"}]},{"@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\/169746","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=169746"}],"version-history":[{"count":0,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/posts\/169746\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=\/wp\/v2\/media\/169747"}],"wp:attachment":[{"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=169746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=169746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=169746"},{"taxonomy":"dealstore","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fdealstore&post=169746"},{"taxonomy":"offerexpiration","embeddable":true,"href":"https:\/\/fivemor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fofferexpiration&post=169746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}