{"id":20075454,"url":"https://github.com/validoll/google_tag_events","last_synced_at":"2025-07-17T07:06:18.989Z","repository":{"id":81416780,"uuid":"188024697","full_name":"validoll/google_tag_events","owner":"validoll","description":"Drupal 8 module provides API to create GTM events infrastructure.","archived":false,"fork":false,"pushed_at":"2024-02-12T10:25:17.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"3.x","last_synced_at":"2025-03-02T12:44:34.347Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/validoll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-22T11:26:29.000Z","updated_at":"2019-07-08T13:40:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"19bacd26-8c1b-419a-bbb3-fdb7f1549af9","html_url":"https://github.com/validoll/google_tag_events","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/validoll/google_tag_events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/validoll%2Fgoogle_tag_events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/validoll%2Fgoogle_tag_events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/validoll%2Fgoogle_tag_events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/validoll%2Fgoogle_tag_events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/validoll","download_url":"https://codeload.github.com/validoll/google_tag_events/tar.gz/refs/heads/3.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/validoll%2Fgoogle_tag_events/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265575502,"owners_count":23790780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T14:59:29.088Z","updated_at":"2025-07-17T07:06:18.984Z","avatar_url":"https://github.com/validoll.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google Tag Manager: Events\n\n## INTRODUCTION\nThe *Google Tag Manager: Events* module provides API to push events\nto GTM Datalayer from PHP.\n\n* For a full description of the module, visit the project page:\n  https://www.drupal.org/project/google_tag_events\n\n* To submit bug reports and feature suggestions, or to track changes:\n  https://www.drupal.org/project/issues/google_tag_events\n\n## REQUIREMENTS\nThis module requires [GoogleTagManager](https://www.drupal.org/project/google_tag) module.\n\n## INSTALLATION\nInstall as you would normally install a contributed Drupal module. Visit:\nhttps://www.drupal.org/docs/extending-drupal/installing-modules\nfor further information.\n\n## CONFIGURATION\nTo push the events via *Google Tag Manager: Events* module you must\nconfigure at least one GTM container.\n\n## FOR DEVELOPERS\nYou can see *gtm_events_test* module for usage examples.\n\n### The goal\nYou can push an event directly from PHP code. It means that event will\nbe pushed after page loading in browser.\n\n### How to push event\nTo push event you can use 'google_tag_events' service.\n\n```php\ngoogle_tag_events_service()-\u003esetEvent(\n  'some_event_name',\n  [\n    'event' =\u003e 'some_event_name'\n    'foo' =\u003e 'bar'\n  ]\n);\n```\n\nAfter this code executing will be pushed event like\n\n```js\ndataLayer.push({\n  'event': 'some_event_name',\n  'foo': 'bar'\n});\n```\n\n### Debug mode\nYou can test GTM events pushing without any configured GTM containers.\nJust enable debug mode on config page */admin/config/system/google-tag/events/settings*.\n\n### How to check\nYou can use recommended browser extensions to check datalayer:\n* [Datalayer Checker](https://chrome.google.com/webstore/detail/datalayer-checker/ffljdddodmkedhkcjhpmdajhjdbkogke) by https://sublimetrix.com\n* [dataslayer](https://chrome.google.com/webstore/detail/dataslayer/ikbablmmjldhamhcdjjigniffkkjgpo) by https://dataslayer.org\n\n### Event plugin\nYou can incapsulate the event data preparation code to event plugin.\nPlugin must be placed into\n`tests/modules/gtm_events_test/src/Plugin/google_tag_event` directory.\n\nFor example:\n\n```php\n/**\n * Node node page visit GTM event plugin.\n *\n * @Plugin(\n *   id = \"example_event_node_view\",\n *   label = @Translation(\"Node page visit event\")\n * )\n */\nclass ExampleEventNodeView extends GoogleTagEventsPluginBase {\n\n  /**\n   * {@inheritdoc}\n   */\n  public function process(array $data = NULL) {\n    $data = $data ?? $this-\u003edata;\n\n    $event_data = [\n      'event' =\u003e 'node_view',\n      'title' =\u003e $data['node']-\u003egetTitle(),\n    ];\n\n    return $event_data;\n  }\n\n}\n```\n\nThen call the service\n\n```php\n/**\n * Implements hook_entity_view().\n */\nfunction comment_entity_view(\n    array \u0026$build,\n    EntityInterface $entity,\n    EntityViewDisplayInterface $display,\n    $view_mode\n  ) {\n  if ($entity instanceof NodeInterface) {\n    google_tag_events_service()-\u003esetEvent(\n      'example_event_node_view',\n      ['node' =\u003e $entity]\n    );\n  }\n}\n```\n\nThe result of this code will be\n\n```js\ndataLayer.push({\n  'event': 'node_view',\n  'title': 'Some node title'\n});\n```\n\nA plugin name must match with event name to call plugin's process method.\n\n## MAINTAINERS\n* Vyacheslav Malchik (validoll) - https://www.drupal.org/u/validoll\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalidoll%2Fgoogle_tag_events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalidoll%2Fgoogle_tag_events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalidoll%2Fgoogle_tag_events/lists"}