mod-build 4.0.75 → 4.0.76-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.76
4
+
5
+ - Added support to load dynamic gtm based on media channels
6
+
3
7
  ## 4.0.75
4
8
 
5
9
  - Updated the seasonal changes regex to include "or" conditions when swapping heating and ac in the strings.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.75",
3
+ "version": "4.0.76-beta.2",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,9 +1,13 @@
1
1
  import hasQsParams from '../has-qs-params.js';
2
+ import updateMediaSpecificGtm from '../update-media-specific-gtm.js';
2
3
 
3
4
  export const useDynamicGtm = (config) => {
4
5
  const { page } = config;
5
6
  if (page.headConfig.useDynamicGtm || typeof window.isQSPage === 'undefined') {
6
7
  hasQsParams();
7
8
  window.gtm_container_ID = window.isQSPage ? config.qs_gtm_container_ID : config.gtm_container_ID;
9
+ if (page.headConfig.updateMediaSpecificGtm) {
10
+ updateMediaSpecificGtm(page.headConfig.updateMediaSpecificGtm);
11
+ }
8
12
  }
9
13
  }
@@ -0,0 +1,28 @@
1
+ export default function (trafficChannels) {
2
+ // trafficChannels is an array of media channels to enable this feature, e.g. ['sem', 'avm'] - we are going to remove this param after testing
3
+ const gtmContainers = {
4
+ 'sem': 'GTM-5WM2R5WC',
5
+ 'avm': 'GTM-TBJV3H',
6
+ 'pub': 'GTM-TBJV3H'
7
+ };
8
+ const urlParams = new URLSearchParams(window.location.search);
9
+ const queryParams = Object.fromEntries(urlParams.entries());
10
+ const url = window.location.href.replace(window.location.hash, '');
11
+ const hasSemIdentifiers = url.includes('gclid') || url.includes('msclkid') || url.includes('=SEM') || url.includes('=sem');
12
+ // const hasQuadlink = 'quadlink' in queryParams; - keeping it for future use
13
+ const hasCCIDorCLK = 'ccid' in queryParams || 'clk' in queryParams;
14
+ const hasAVMParam = queryParams.channel && queryParams.channel.toLowerCase() === 'avm';
15
+ let mediaChannel = 'pub';
16
+
17
+ if (hasAVMParam) {
18
+ mediaChannel = 'avm';
19
+ }
20
+
21
+ if (hasSemIdentifiers && !hasCCIDorCLK && !hasAVMParam) {
22
+ mediaChannel = 'sem';
23
+ }
24
+
25
+ if (trafficChannels.includes(mediaChannel) && gtmContainers[mediaChannel]) {
26
+ window.gtm_container_ID = gtmContainers[mediaChannel];
27
+ }
28
+ }