diff --git a/integrations/google-analytics-4/HISTORY.md b/integrations/google-analytics-4/HISTORY.md
index 8b0fa67d0..7d78e6f8c 100644
--- a/integrations/google-analytics-4/HISTORY.md
+++ b/integrations/google-analytics-4/HISTORY.md
@@ -1,3 +1,8 @@
+0.1.0 / 2025-03-19
+==================
+
+ * Add support for custom domain configuration for gtag.js script loading
+
0.0.2 / 2021-03-24
==================
diff --git a/integrations/google-analytics-4/lib/index.js b/integrations/google-analytics-4/lib/index.js
index b5daacfe0..d8d0c0a32 100644
--- a/integrations/google-analytics-4/lib/index.js
+++ b/integrations/google-analytics-4/lib/index.js
@@ -13,6 +13,7 @@ var GA4 = (module.exports = integration('Google Analytics 4')
.global('gtag')
.global('ga4DataLayer')
.option('measurementIds', [])
+ .option('domain', 'www.googletagmanager.com')
.option('cookieDomainName', 'auto')
.option('cookiePrefix', '_ga')
.option('cookieExpiration', 63072000)
@@ -48,7 +49,7 @@ var GA4 = (module.exports = integration('Google Analytics 4')
*/
.option('customEventsAndParameters', [])
.tag(
- '')
});
+
+ it('should load gtag.js with the custom domain', function () {
+ ga4.options.domain = 'custom.example.com';
+ analytics.initialize();
+ analytics.called(ga4.load)
+ analytics.loaded('')
+ });
});
});
@@ -124,6 +132,13 @@ describe('Google Analytics 4', function () {
analytics.equal(window.ga4DataLayer[2][2]['send_page_view'], false)
});
+ it('should set the server_container_url for all measurement IDs', function () {
+ ga4.options.domain = 'https://custom.example.com';
+ analytics.initialize();
+ analytics.equal(window.ga4DataLayer[1][2]['server_container_url'], 'https://custom.example.com')
+ analytics.equal(window.ga4DataLayer[2][2]['server_container_url'], 'https://custom.example.com')
+ });
+
it('should set cookie related setting for all measurement IDs', function () {
ga4.options.cookieUpdate = false;
ga4.options.cookieDomainName = 'ajs.test'
diff --git a/integrations/google-analytics-4/test/index.test.js b/integrations/google-analytics-4/test/index.test.js
new file mode 100644
index 000000000..f5f02e0d6
--- /dev/null
+++ b/integrations/google-analytics-4/test/index.test.js
@@ -0,0 +1,34 @@
+'use strict';
+
+var Analytics = require('@segment/analytics.js-core').constructor;
+var integration = require('@segment/analytics.js-integration');
+var sandbox = require('@segment/clear-env');
+var tester = require('@segment/analytics.js-integration-tester');
+var GA4 = require('../lib/');
+
+describe('Google Analytics 4', function() {
+ var analytics;
+ var ga4;
+ var options = {
+ containerId: 'GTM-XXXX',
+ environment: '',
+ domain: 'www.googletagmanager.com',
+ trackNamedPages: true,
+ trackCategorizedPages: true
+ };
+
+ beforeEach(function() {
+ analytics = new Analytics();
+ ga4 = new GA4(options);
+ analytics.use(GA4);
+ analytics.use(tester);
+ analytics.add(ga4);
+ });
+
+ afterEach(function() {
+ analytics.restore();
+ analytics.reset();
+ ga4.reset();
+ sandbox();
+ });
+});
\ No newline at end of file
diff --git a/integrations/google-tag-manager/HISTORY.md b/integrations/google-tag-manager/HISTORY.md
index 988eb286a..d6be67a94 100644
--- a/integrations/google-tag-manager/HISTORY.md
+++ b/integrations/google-tag-manager/HISTORY.md
@@ -1,3 +1,8 @@
+2.6.0 / 2025-03-19
+==================
+
+ * Add support for custom domain configuration for GTM script loading
+
2.5.0 / 2017-04-27
==================
diff --git a/integrations/google-tag-manager/lib/index.js b/integrations/google-tag-manager/lib/index.js
index f3e757369..07903d2ec 100644
--- a/integrations/google-tag-manager/lib/index.js
+++ b/integrations/google-tag-manager/lib/index.js
@@ -16,15 +16,16 @@ var GTM = (module.exports = integration('Google Tag Manager')
.global('google_tag_manager')
.option('containerId', '')
.option('environment', '')
+ .option('domain', 'www.googletagmanager.com')
.option('trackNamedPages', true)
.option('trackCategorizedPages', true)
.tag(
'no-env',
- '