Skip to content

Commit

Permalink
Option to delay loading GTM until user interaction is triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Jun 19, 2023
1 parent a7b7a74 commit fad2369
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.4.0] - 19 June 2023
### Added
- Delay loading GTM until user interaction is triggered
- Option to delay loading GTM until user interaction is triggered

## [3.3.4] - 16 June 2023
### Fixed
Expand Down
10 changes: 10 additions & 0 deletions Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public function isDebug(): bool
return (bool)$this->getModuleConfigValue('debug');
}

/**
* Wait for user interaction to start
*
* @return bool
*/
public function waitForUserInteraction(): bool
{
return (bool)$this->getModuleConfigValue('wait_for_ui');
}

/**
* Check whether mouse clicks are debugged as well
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yireo/magento2-googletagmanager2",
"version": "3.3.4",
"version": "3.4.0",
"license": "OSL-3.0",
"type": "magento2-module",
"homepage": "https://www.yireo.com/software/magento-extensions/googletagmanager2",
Expand Down
7 changes: 7 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
<field id="debug">1</field>
</depends>
</field>
<field id="wait_for_ui" type="select" translate="label" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Wait for user interaction</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="category_products" translate="label" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Maximum Products in Category</label>
<comment>Maximum number of products to load in a specific category overview. 0 to disable</comment>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<enabled>0</enabled>
<id/>
<debug>0</debug>
<wait_for_ui>0</wait_for_ui>
<category_products>3</category_products>
<product_eav_attributes>material</product_eav_attributes>
<category_eav_attributes>id,name</category_eav_attributes>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/templates/script.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $config = $block->getConfig();
events.forEach(function (eventType) {
window.addEventListener(eventType, initYireoGoogleTagManager2, {once: true, passive: true})
})
})(['keydown', 'mouseover', 'scroll', 'touchstart', 'wheel']);
})([<?php if ($config->waitForUserInteraction() === false) : ?>'load', <?php endif; ?>'keydown', 'mouseover', 'scroll', 'touchstart', 'wheel']);
</script>

<?php if ($config->isDebug()): ?>
Expand Down

0 comments on commit fad2369

Please sign in to comment.