Skip to content

firozhc/google-tag-manager

Repository files navigation

google-tag-manager

Steps

Personal Access Token - 43ea15aa8a47834a7fdcb0a16538d747efa2abc9

  1. Create GTM Account and Container
  2. Enable GTM API from Google API Console

client id - 123054155439-5po5550bbaavikre8vog27ngtbmjgn7f.apps.googleusercontent.com client secret - ZP4fluSDvTRyDcdAtc-TQjHo

  1. get list of account for user and extract account ids - GET https://www.googleapis.com/tagmanager/v2/accounts
  2. {
  3. "account": [
  4. {
  5. "path": "accounts/1853485978",
  6. "accountId": "1853485978",
  7. "name": "Demo"
  8. },
  9. {
  10. "path": "accounts/1404042777",
  11. "accountId": "1404042777",
  12. "name": "TheMaverickAtWork"
  13. },
  14. {
  15. "path": "accounts/4521840438",
  16. "accountId": "4521840438",
  17. "name": "Test"
  18. }
  19. ]
  20. }
  21. call get container method using account id -
  22. GET https://www.googleapis.com/tagmanager/v2/+parent/containers
  23. GET https://www.googleapis.com/tagmanager/v2/accounts/4521840438/containers
  24. extract the relevant containers public id
  25. {
  26. "container": [
  27. {
  28. "path": "accounts/4521840438/containers/10524766",
  29. "accountId": "4521840438",
  30. "containerId": "10524766",
  31. "name": "testcontainer",
  32. "publicId": "GTM-KB5S87G",
  33. "usageContext": [
  34. "web"
    
  35. ],
  36. "fingerprint": "1543440285059",
  37. "tagManagerUrl": "https://tagmanager.google.com/#/container/accounts/4521840438/containers/10524766/workspaces?apiLink=container"
  38. },
  39. {
  40. "path": "accounts/4521840438/containers/10525729",
  41. "accountId": "4521840438",
  42. "containerId": "10525729",
  43. "name": "Greetings",
  44. "publicId": "GTM-MXB9B22",
  45. "usageContext": [
  46. "web"
    
  47. ],
  48. "fingerprint": "1543474110180",
  49. "tagManagerUrl": "https://tagmanager.google.com/#/container/accounts/4521840438/containers/10525729/workspaces?apiLink=container"
  50. }
  51. ]
  52. }
  53. embed the relevant containers public id into page script
  54. head tag
  55. <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  56. new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  57. j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  58. 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  59. })(window,document,'script','dataLayer','GTM-MXB9B22');</script>
  60. body tag
  61. <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-MXB9B22"
  62. height="0" width="0" style="display:none;visibility:hidden"></iframe>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published