Skills › Marketing Skills › conversion-tracking › detect-thank-you-page.json
detect-thank-you-page.json
81 lines · skills/conversion-tracking/assets/gtm-recipes/detect/detect-thank-you-page.json at 88c79f6
1{
2 "exportFormatVersion": 2,
3 "containerVersion": {
4 "path": "accounts/0/containers/0",
5 "accountId": "0",
6 "containerId": "0",
7 "containerVersionId": "0",
8 "container": {
9 "path": "accounts/0/containers/0",
10 "accountId": "0",
11 "containerId": "0",
12 "name": "Conversion Detection - Thank-you page",
13 "publicId": "GTM-XXXXXXX",
14 "usageContext": [
15 "WEB"
16 ],
17 "fingerprint": "0",
18 "tagManagerUrl": "https://tagmanager.google.com/#/container/accounts/0/containers/0/workspaces/0"
19 },
20 "tag": [
21 {
22 "accountId": "0",
23 "containerId": "0",
24 "tagId": "1",
25 "name": "Conversion Detection - Thank-you page Listener",
26 "type": "html",
27 "parameter": [
28 {
29 "type": "TEMPLATE",
30 "key": "html",
31 "value": "<script>\n(function () {\n if (window.__ctDetectThankYouPage) return;\n window.__ctDetectThankYouPage = true;\n window.dataLayer = window.dataLayer || [];\n\n /* ---------------------------------------------------------------\n EDIT THIS. Paths that mean \"the conversion happened\".\n Matched against location.pathname, case-insensitively, as a\n prefix. '/thank-you' matches '/thank-you' and '/thank-you/order/9'.\n --------------------------------------------------------------- */\n var THANK_YOU_PATHS = [\n '/thank-you',\n '/thanks',\n '/confirmation',\n '/success'\n ];\n\n // Set true only if your confirmation page is genuinely reachable more than\n // once per conversion and you want every view counted. Leave false.\n var COUNT_EVERY_VIEW = false;\n\n var fired = {};\n\n function matches(path) {\n var p = String(path || '').toLowerCase();\n for (var i = 0; i < THANK_YOU_PATHS.length; i++) {\n var want = String(THANK_YOU_PATHS[i] || '').toLowerCase();\n if (want && p.indexOf(want) === 0) return want;\n }\n return null;\n }\n\n function check() {\n try {\n var path = window.location.pathname;\n var matched = matches(path);\n if (!matched) return;\n\n // A refresh or a back-button return to the confirmation page would\n // otherwise count a second conversion for the same lead. Keyed on the\n // full path so two different confirmations still both count.\n if (!COUNT_EVERY_VIEW && fired[path]) return;\n fired[path] = true;\n\n window.dataLayer.push({\n event: 'thank_you_page_view',\n page_path: path,\n matched_rule: matched\n });\n } catch (e) {\n // Never throw back into the page.\n }\n }\n\n // Single-page apps are the reason this is not just a one-shot call. A\n // React, Vue or Next site changes the URL without a page load, so no\n // pageview ever fires and a thank-you page TRIGGER silently counts zero.\n // Wrapping history means we see those route changes too.\n function wrapHistory(method) {\n var original = window.history[method];\n if (typeof original !== 'function') return;\n window.history[method] = function () {\n var result = original.apply(this, arguments);\n try { setTimeout(check, 0); } catch (e) { /* ignore */ }\n return result;\n };\n }\n\n try {\n wrapHistory('pushState');\n wrapHistory('replaceState');\n window.addEventListener('popstate', function () { setTimeout(check, 0); });\n } catch (e) {\n // History API unavailable — the initial check below still runs.\n }\n\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', check);\n } else {\n check();\n }\n})();\n</script>"
32 },
33 {
34 "type": "BOOLEAN",
35 "key": "supportDocumentWrite",
36 "value": "false"
37 }
38 ],
39 "firingTriggerId": [
40 "2147479553"
41 ],
42 "tagFiringOption": "ONCE_PER_EVENT",
43 "monitoringMetadata": {
44 "type": "MAP"
45 },
46 "consentSettings": {
47 "consentStatus": "NOT_SET"
48 }
49 }
50 ],
51 "trigger": [
52 {
53 "accountId": "0",
54 "containerId": "0",
55 "triggerId": "2",
56 "name": "CE - Thank-you page",
57 "type": "CUSTOM_EVENT",
58 "customEventFilter": [
59 {
60 "type": "EQUALS",
61 "parameter": [
62 {
63 "type": "TEMPLATE",
64 "key": "arg0",
65 "value": "{{_event}}"
66 },
67 {
68 "type": "TEMPLATE",
69 "key": "arg1",
70 "value": "thank_you_page_view"
71 }
72 ]
73 }
74 ],
75 "filter": []
76 }
77 ],
78 "variable": [],
79 "fingerprint": "0"
80 }
81}