{"id":1224,"date":"2023-04-22T17:55:01","date_gmt":"2023-04-22T16:55:01","guid":{"rendered":"https:\/\/organicdigital.co\/blog\/?p=1224"},"modified":"2025-03-11T10:54:00","modified_gmt":"2025-03-11T10:54:00","slug":"how-to-use-chatgpt-ai-with-gtm","status":"publish","type":"post","link":"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/","title":{"rendered":"How To: Use ChatGPT AI with GTM"},"content":{"rendered":"\n<p>As a <a href=\"https:\/\/daveashworth.co\/\">website optimisation consultant<\/a> I&#8217;m excited to see where AI can help me on my projects and client work. That I&#8217;ve found ways to make my GTM tasks quicker and more efficient makes me very happy.<\/p>\n\n\n\n<p><a href=\"https:\/\/daveashworth.co\/skills\/google-tag-manager-consultant\/\">Google Tag Manager<\/a> has come a long way since it\u2019s inception back in October 2012, when it\u2019s primary use was to insert tracking code snippets to a website without the need for a developer or skilled coder.<\/p>\n\n\n\n<p>With the development a wide range functionality in the context of tags, triggers and custom variables, it\u2019s become a powerful tool with regards manipulating a webpage in terms of either extracting data for <a href=\"https:\/\/daveashworth.co\/skills\/analytics-and-ad-tracking-consultant\/google-analytics-4\/\">bespoke tracking configuration<\/a> or inserting code for SEO, UX or indeed for any reason at all for which you might want to amend the code or content on a page.<\/p>\n\n\n\n<p>In turn, the need of an understanding of web coding in terms of HTML, CSS and JavaScript has become fundamental.<\/p>\n\n\n\n<p>Despite having a background in coding, it doesn\u2019t mean I want to spend much time coming up with the code that is required to do the things I need to do.&nbsp; Back when I was an actual developer, the go to place was Experts Exchange.&nbsp; Until recently, I\u2019d find myself on stackoverflow.com.<\/p>\n\n\n\n<p>However, life got much easier since <a href=\"https:\/\/chat.openai.com\/\" target=\"_blank\" rel=\"noopener\">ChatGPT<\/a> came along.<\/p>\n\n\n\n<p>This isn\u2019t a blog post about ChatGPT and what it can do, if you want to find out more, this is as a good an article as any.<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/www.zdnet.com\/article\/what-is-chatgpt-and-why-does-it-matter-heres-everything-you-need-to-know\/\" target=\"_blank\" rel=\"noopener\">zdnet.com: What is ChatGPT and why does it matter? Here&#8217;s what you need to know<\/a><\/strong><\/p>\n\n\n\n<p>Am going to assume that you have an understanding of ChatGTP and Google Tag Manager from here on in (but if you have any questions that arise from reading this, feel free to get in touch).<\/p>\n\n\n\n<p>So, what can you do in GTM with the help of AI? <\/p>\n\n\n\n<p>I guess the actual answer is &#8220;anything&#8221;, but so far, this is how I&#8217;ve used it:<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/#Write_Custom_JS_Variables\" >Write Custom JS Variables<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/#Extract_PDF_name_from_path\" >Extract PDF name from path<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/#Format_Email_or_Telephone_Number_Click_Text\" >Format Email or Telephone Number Click Text<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/#Format_all_upper_case_page_titles\" >Format all upper case page titles<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/#Resolve_JavaScript_Coding_Errors\" >Resolve JavaScript Coding Errors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/#Write_Regular_Expressions\" >Write Regular Expressions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/#Write_A_Custom_HTML_Listener\" >Write A Custom HTML Listener<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/daveashworth.co\/blog\/how-to-use-chatgpt-ai-with-gtm\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_Custom_JS_Variables\"><\/span>Write Custom JS Variables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The main area I\u2019ve used ChatGPT is to create custom JavaScript variables to format existing variables into user friendly strings to then use for custom events within GA4 tracking.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extract_PDF_name_from_path\"><\/span><strong>Extract PDF name from path<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>by default, the file_download event tracks the file name as the full path, e.g.<br>\/directory\/uploads\/folder\/filename.pdf<br><br>however, I asked ChatGPT to write me a function that extracted just the filename from the Click URL as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"602\" height=\"581\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chatgpt_prompt_pdf.png\" alt=\"chatgpt prompt pdf\" class=\"wp-image-1226\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chatgpt_prompt_pdf.png 602w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chatgpt_prompt_pdf-300x290.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chatgpt_prompt_pdf-150x145.png 150w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p>and just like that I have code that can be adapted for use within a Custom JS Variable which takes the Click URL as the input:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function()\n{\n  var this_url = {{Click URL}};\n  var url_parts = this_url.split(\"\/\");\n  return url_parts&#91;url_parts.length - 1];\n}\n<\/code><\/pre>\n\n\n\n<p>In this case, I call this variable \u201ccJS \u2013 PDF\u201d<br><br>That can then be added to a custom event:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"488\" height=\"344\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf.png\" alt=\"click_pdf event\" class=\"wp-image-1227\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf.png 488w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf-300x211.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf-150x106.png 150w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/figure>\n\n\n\n<p>which makes for a much cleaner looking report:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"335\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf_report-1024x335.png\" alt=\"click_pdf report\" class=\"wp-image-1228\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf_report-1024x335.png 1024w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf_report-300x98.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf_report-150x49.png 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf_report-768x251.png 768w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_pdf_report.png 1191w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Format_Email_or_Telephone_Number_Click_Text\"><\/span>Format Email or Telephone Number Click Text<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Similar to the above, if you want to track which emails or telephone numbers are clicked on your site, but don\u2019t want the report to contain tel: or mailto:, then just ask:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"614\" height=\"326\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_email.png\" alt=\"click_emil prompt\" class=\"wp-image-1229\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_email.png 614w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_email-300x159.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_email-150x80.png 150w\" sizes=\"(max-width: 614px) 100vw, 614px\" \/><\/figure>\n\n\n\n<p>which is amended to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function()\n{\n  var email_address = \"{{Click URL}}\";\n  if (email_address.startsWith(\"mailto:\")) {\n    return email_address.slice(7);\n  } else {\n    return email_address;\n  } \n}\n\n<\/code><\/pre>\n\n\n\n<p>or for telephone numbers:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"622\" height=\"334\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_tel-1.png\" alt=\"click_tel  prompt\" class=\"wp-image-1231\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_tel-1.png 622w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_tel-1-300x161.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_tel-1-150x81.png 150w\" sizes=\"(max-width: 622px) 100vw, 622px\" \/><\/figure>\n\n\n\n<p>which is amended to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function()\n{\n  var phone_number = \"{{Click URL}}\";\n  if (phone_number.startsWith(\"tel:\")) {\n    return phone_number.slice(4);\n  } else {\n    return phone_number;\n  } \n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Format_all_upper_case_page_titles\"><\/span><strong>Format all upper case page titles<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I often create a social share event that indicates when a page or post has been shared to social media when share buttons have been clicked.&nbsp; As well as the platform and page path, I send the page title which is pulled in from the H1 tag.&nbsp; On a recent site, the H1 was capitalised which I didn\u2019t want in the report, so asked for a function to convert so that only the first letter was a capital:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"625\" height=\"297\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/titleCase_prompt.png\" alt=\"titleCase prompt\" class=\"wp-image-1232\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/titleCase_prompt.png 625w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/titleCase_prompt-300x143.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/titleCase_prompt-150x71.png 150w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<p>which is amended to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ()\n{\n  var this_h1 = {{h1.title}};\n  return this_h1.toLowerCase().replace(\/(^|\\s)\\S\/g, function(firstLetter) {\n    return firstLetter.toUpperCase();\n  });\n}\n<\/code><\/pre>\n\n\n\n<p>The above examples aren\u2019t the most complex of functions, and with some time, thought and research, I could have wrote these myself. &nbsp;However, asking ChatGPT to do this saved a considerable amount of time, and I can then use my JS \/ code knowledge to take the output and convert to the required format for tag manager.<\/p>\n\n\n\n<p>But as you can see, AI generated code is the future.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Resolve_JavaScript_Coding_Errors\"><\/span><strong>Resolve JavaScript Coding Errors<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes, you may attempt to write your own code that doesn\u2019t work.<\/p>\n\n\n\n<p>In fact, ChatGPT may generate code that doesn\u2019t work.<\/p>\n\n\n\n<p>But if you prompt it with the error that is generated by the code you are tyring to implement, it will be more than likely able to fix it.<\/p>\n\n\n\n<p>For example, when I first asked it to write me the code above to amend upper and lower case characters in a string, I got the following output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"602\" height=\"658\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/capitalise_v1.jpg\" alt=\"capitalise_v1\" class=\"wp-image-1233\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/capitalise_v1.jpg 602w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/capitalise_v1-274x300.jpg 274w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/capitalise_v1-137x150.jpg 137w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<p>When I tried to preview the code in GTM I got the following error:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"496\" height=\"260\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/gtm_error.png\" alt=\"GTM error\" class=\"wp-image-1234\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/gtm_error.png 496w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/gtm_error-300x157.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/gtm_error-150x79.png 150w\" sizes=\"(max-width: 496px) 100vw, 496px\" \/><\/figure>\n\n\n\n<p>So I informed ChatGPT of this, it apologised, then provided updated code which worked:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"602\" height=\"577\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/capitalise_v2.jpg\" alt=\"capitalise_v2\" class=\"wp-image-1235\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/capitalise_v2.jpg 602w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/capitalise_v2-300x288.jpg 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/capitalise_v2-150x144.jpg 150w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_Regular_Expressions\"><\/span>Write Regular Expressions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Over the years I\u2019ve become proficient in the following languages:<\/p>\n\n\n\n<p>ASP, HTML, CSS, JS, Coldfusion, SQL and PHP<\/p>\n\n\n\n<p>However, I have NEVER got my head around RegEx.&nbsp; I can\u2019t do it and shy away as soon as my first attempt doesn\u2019t work.<\/p>\n\n\n\n<p>Not anymore though.<\/p>\n\n\n\n<p>One of the custom events I create as part of my GA4 configurations is to track internal links clicked on a page and whether they are clicked in the header, main content or footer.<\/p>\n\n\n\n<p>I do this my setting the click URL trigger to match the site domain so as not to confuse it for an external link click.<\/p>\n\n\n\n<p>Recently, I was working on a site that had internal linking between the subdomains www, shop, member and tickets.<\/p>\n\n\n\n<p>So I needed a trigger that would match the Click URL to any of those subdomains:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"554\" height=\"686\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/subdomains_prompt.png\" alt=\"subdomains prompt\" class=\"wp-image-1236\" style=\"width:554px;height:686px\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/subdomains_prompt.png 554w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/subdomains_prompt-242x300.png 242w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/subdomains_prompt-121x150.png 121w\" sizes=\"(max-width: 554px) 100vw, 554px\" \/><\/figure>\n\n\n\n<p>And it works a treat:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"789\" height=\"468\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_page_content.png\" alt=\"click page content\" class=\"wp-image-1237\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_page_content.png 789w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_page_content-300x178.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_page_content-150x89.png 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/click_page_content-768x456.png 768w\" sizes=\"(max-width: 789px) 100vw, 789px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_A_Custom_HTML_Listener\"><\/span><strong>Write A Custom HTML Listener<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is something that I\u2019ve never done until recently upon the request of a client.&nbsp; They create a lot of useful content on there site, which they are happy for users to copy and paste for use elsewhere. They wanted to know how often this was happening, on which pages, and what text.<\/p>\n\n\n\n<p>Under normal circumstances I would\u2019ve spent some time trying to figure out how to do this.<\/p>\n\n\n\n<p>Now, you just need to think about the level of detail required in your prompt:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"627\" height=\"765\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/listener_prompt.png\" alt=\"Write A Custom HTML Listener\" class=\"wp-image-1238\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/listener_prompt.png 627w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/listener_prompt-246x300.png 246w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/listener_prompt-123x150.png 123w\" sizes=\"(max-width: 627px) 100vw, 627px\" \/><\/figure>\n\n\n\n<p>This is then added as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script&gt;\n  document.addEventListener('copy', function(event) {\n    var copiedText = window.getSelection().toString();\n    var pageUrl = window.location.href;\n    dataLayer.push({\n      'event': 'copy_text',\n      'copiedText': copiedText,\n      'pageUrl': {{Page Path}}\n    });\n  });\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"833\" height=\"680\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chtml.png\" alt=\"chtml\" class=\"wp-image-1239\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chtml.png 833w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chtml-300x245.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chtml-150x122.png 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/chtml-768x627.png 768w\" sizes=\"(max-width: 833px) 100vw, 833px\" \/><\/figure>\n\n\n\n<p>Then create variables to pull in the text from the data layer, and a custom event trigger that calls the GA4 Event:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"801\" height=\"357\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/dlv.png\" alt=\"variable\" class=\"wp-image-1240\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/dlv.png 801w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/dlv-300x134.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/dlv-150x67.png 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/dlv-768x342.png 768w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"791\" height=\"371\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/custom_event.png\" alt=\"custom event\" class=\"wp-image-1241\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/custom_event.png 791w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/custom_event-300x141.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/custom_event-150x70.png 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/custom_event-768x360.png 768w\" sizes=\"(max-width: 791px) 100vw, 791px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"846\" height=\"613\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/ga4_event.png\" alt=\"event ga4 cxopy text\" class=\"wp-image-1242\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/ga4_event.png 846w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/ga4_event-300x217.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/ga4_event-150x109.png 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/ga4_event-768x556.png 768w\" sizes=\"(max-width: 846px) 100vw, 846px\" \/><\/figure>\n\n\n\n<p>Which then fires as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"377\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/copy_text-1024x377.png\" alt=\"copying text\" class=\"wp-image-1243\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/copy_text-1024x377.png 1024w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/copy_text-300x110.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/copy_text-150x55.png 150w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/copy_text-768x283.png 768w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/copy_text.png 1078w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"439\" height=\"337\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/gtm_tab.png\" alt=\"gtm debugger \" class=\"wp-image-1244\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/gtm_tab.png 439w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/gtm_tab-300x230.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/gtm_tab-150x115.png 150w\" sizes=\"(max-width: 439px) 100vw, 439px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"530\" height=\"493\" src=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/event_fired.png\" alt=\"tag details\" class=\"wp-image-1245\" srcset=\"https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/event_fired.png 530w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/event_fired-300x279.png 300w, https:\/\/daveashworth.co\/blog\/wp-content\/uploads\/2023\/04\/event_fired-150x140.png 150w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The examples above are just the start of how you can start to use ChatGPT or any other AI solution in your every day SEO\/GTM\/GA4 tasks.<\/p>\n\n\n\n<p>The key I always find is the quality of your prompt.&nbsp; You can chat away to generate ideas and get inspired, but once you know what you want, be specific and you\u2019ll probably end up with some highly useful code or content that does exactly what you need it to do.<\/p>\n\n\n\n<p>Good luck.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An exploration into how to use ChatFPT AI in conjunction with Google Tag Manager (GTM).  Find out how to automate workflow, save time and simplify tasks.<\/p>\n","protected":false},"author":1,"featured_media":1225,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tag-manager"],"_links":{"self":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/1224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/comments?post=1224"}],"version-history":[{"count":0,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/posts\/1224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/media\/1225"}],"wp:attachment":[{"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/media?parent=1224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/categories?post=1224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daveashworth.co\/blog\/wp-json\/wp\/v2\/tags?post=1224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}