gatsby-core-theme 30.0.24 → 30.0.26

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,3 +1,20 @@
1
+ ## [30.0.26](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v30.0.25...v30.0.26) (2023-11-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * tracker optimizations ([7a00e03](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/7a00e03c1b50fc7b7f58df3611d1f1095809e524))
7
+
8
+
9
+ * Merge branch 'tm-3833-tracker-optimizations' into 'master' ([9032562](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/903256263606a1c14c030954d984a7e45d291071))
10
+
11
+ ## [30.0.25](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v30.0.24...v30.0.25) (2023-11-29)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * tracker SSR optimizations ([9968c54](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/9968c544e423a3671f0edce7d5cfba1831099b09))
17
+
1
18
  ## [30.0.24](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v30.0.23...v30.0.24) (2023-11-23)
2
19
 
3
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-core-theme",
3
- "version": "30.0.24",
3
+ "version": "30.0.26",
4
4
  "description": "Gatsby Theme NPM Package",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -3,6 +3,7 @@ import React, { useContext } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { Context } from '~context/MainProvider';
5
5
  import { prettyTracker, translate } from '~helpers/getters';
6
+ import { setCookie, getCookie } from '~helpers/cookies';
6
7
 
7
8
  import styles from './button.module.scss';
8
9
 
@@ -26,18 +27,27 @@ const OperatorCtaButton = ({
26
27
  const { translations } = useContext(Context) || {};
27
28
  const status = operator?.status || '';
28
29
  const trackerType = tracker?.toLowerCase()?.replace(' ', '_');
29
-
30
- const urlParams = [];
30
+ const url = typeof window !== 'undefined' ? window.location.href : '';
31
+ const urlParams = {};
31
32
 
32
33
  if (process.env.IS_TRACKING_SSR === 'true') {
33
- pageTemplate && urlParams.push(`template=${pageTemplate}`);
34
- module && urlParams.push(`module=${module}`);
35
- tracker !== 'main' && urlParams.push(`tracker_name=${tracker}`);
34
+ if (pageTemplate) {
35
+ urlParams.page_type = pageTemplate;
36
+ }
37
+ if (module) {
38
+ urlParams.module = module;
39
+ }
40
+ if (tracker !== 'main') {
41
+ urlParams.tracker_name = tracker;
42
+ }
43
+ urlParams.request_url = url;
36
44
  }
37
45
 
38
- const prettyLink = `${prettyTracker(operator, trackerType, false, pageTemplate)}${
39
- urlParams.length > 0 ? `?${urlParams.join('&')}` : ''
40
- }`;
46
+ const prettyLink = `${prettyTracker(operator, trackerType, false, pageTemplate)}`;
47
+
48
+ const onCTAClick = () => {
49
+ process.env.IS_TRACKING_SSR && setCookie('affObject', JSON.stringify(urlParams));
50
+ };
41
51
 
42
52
  const translateBtn =
43
53
  status && translationsObj[status]
@@ -60,6 +70,7 @@ const OperatorCtaButton = ({
60
70
  className={`${classes} ${gtmClass}`}
61
71
  target="_blank"
62
72
  rel="nofollow noreferrer sponsored"
73
+ onClick={onCTAClick}
63
74
  >
64
75
  {translateBtn}
65
76
  {icon && icon}
@@ -3,9 +3,8 @@ import PropTypes from 'prop-types';
3
3
  import Button from '~atoms/button/button';
4
4
  import LazyImage from '~hooks/lazy-image';
5
5
  import { imagePrettyUrl, getAltText, translate } from '~helpers/getters';
6
- import { generateTrackerLink } from '~helpers/generators';
7
6
  import styles from './tracker.module.scss';
8
- import { getAffiliateLink } from '~helpers/tracker';
7
+ import { getAffiliateLink, getTrackerName } from '~helpers/tracker';
9
8
 
10
9
  const Tracker = ({
11
10
  pageContext,
@@ -26,29 +25,8 @@ const Tracker = ({
26
25
  }) => {
27
26
  const { operator, page } = pageContext;
28
27
  const translations = page?.translations;
29
- const trackerLinks = operator ? Object.keys(operator.links) : [];
30
28
 
31
- const stripTrailingSlash = (str) => (str.endsWith('/') ? str.slice(0, -1) : str);
32
-
33
- let tracker = '';
34
- for (let i = 0; i < trackerLinks.length; i += 1) {
35
- const trackerLink = trackerLinks[i].toLowerCase().replace(' ', '_');
36
- if (
37
- generateTrackerLink(operator, trackerLink, false, page.template) === stripTrailingSlash(path)
38
- ) {
39
- tracker =
40
- operator.links[
41
- Object.keys(operator.links).find((key) => key.toLowerCase() === trackerLink.toLowerCase())
42
- ];
43
- break;
44
- }
45
- if (path.includes('ppc_fallback')) {
46
- // eslint-disable-next-line react/prop-types
47
- tracker = operator.links['PPC Fallback'];
48
- break;
49
- }
50
- tracker = operator.links.main;
51
- }
29
+ const tracker = getTrackerName(operator, page, path);
52
30
 
53
31
  const showSplashScreen = typeof window !== 'undefined';
54
32
 
@@ -59,7 +37,7 @@ const Tracker = ({
59
37
  window.location.replace(serverData.result.link);
60
38
  } else {
61
39
  console.log('FROM LOCAL');
62
- window.location.replace(tracker);
40
+ window.location.replace(tracker.value);
63
41
  }
64
42
  }
65
43
  }
@@ -195,10 +173,15 @@ Tracker.propTypes = {
195
173
  styles: PropTypes.shape({}),
196
174
  };
197
175
 
198
- export async function getServerData({ pageContext, url }) {
176
+ export async function getServerData({ pageContext, headers, url }) {
199
177
  let res = '';
200
-
201
- res = await getAffiliateLink(pageContext.operator, url);
178
+ res = await getAffiliateLink(
179
+ pageContext.operator,
180
+ url,
181
+ pageContext.page.path,
182
+ pageContext.page,
183
+ headers
184
+ );
202
185
  return res;
203
186
  }
204
187
 
@@ -1,18 +1,59 @@
1
- /* eslint-disable import/prefer-default-export */
2
- export async function getAffiliateLink(operator, url) {
3
- let urlParams = `site_id=${process.env.SITE_ID}&operator_short_name=${
4
- operator.short_name
5
- }&operator_type=${operator.type}&language=${operator.market.split('_')[1]}&market_short_code=${
6
- operator.market
7
- }`;
1
+ import { generateTrackerLink } from '~helpers/generators';
8
2
 
9
- const urlSplit = url.split('?');
10
3
 
11
- if (urlSplit.length === 2) {
12
- urlParams += `&${urlSplit[1]}`;
4
+ export function getTrackerName(operator, page, path) {
5
+ const trackerLinks = operator ? Object.keys(operator.links) : [];
6
+ const stripTrailingSlash = (str) => (str.endsWith('/') ? str.slice(0, -1) : str);
7
+ let trackerName = 'main';
8
+ let tracker = '';
9
+ for (let i = 0; i < trackerLinks.length; i += 1) {
10
+ const trackerLink = trackerLinks[i].toLowerCase().replace(' ', '_');
11
+ if (
12
+ generateTrackerLink(operator, trackerLink, false, page.template) === stripTrailingSlash(path)
13
+ ) {
14
+ tracker =
15
+ operator.links[
16
+ Object.keys(operator.links).find((key) => key.toLowerCase() === trackerLink.toLowerCase())
17
+ ];
18
+ trackerName = trackerLink.toLowerCase();
19
+ break;
20
+ }
21
+ if (path.includes('ppc_fallback')) {
22
+ // eslint-disable-next-line react/prop-types
23
+ tracker = operator.links['PPC Fallback'];
24
+ break;
25
+ }
26
+ tracker = operator.links.main;
13
27
  }
14
28
 
15
- const res = await fetch(`${process.env.GATSBY_TRACKING_API_URL}?${urlParams}`).catch(
29
+ return { name: trackerName, value: tracker };
30
+ }
31
+
32
+ /* eslint-disable no-return-assign */
33
+ /* eslint-disable import/prefer-default-export */
34
+ export async function getAffiliateLink(operator, url, path, page, headers) {
35
+ const trackerName = await getTrackerName(operator, page, path);
36
+
37
+ const cookie =
38
+ headers.get('cookie') &&
39
+ headers
40
+ .get('cookie')
41
+ .split(';')
42
+ .map((item) => item.split('='))
43
+ .reduce((acc, [k, v]) => (acc[k.trim().replace('"', '')] = v) && acc, {});
44
+
45
+ const urlParam = {
46
+ site_id: process.env.SITE_ID,
47
+ operator_short_name: operator.short_name,
48
+ operator_type: operator.type,
49
+ language: operator.market.split('_')[1],
50
+ tracker_name: trackerName.name,
51
+ market_short_code: operator.market,
52
+ ip_address: headers.get('host'),
53
+ ...JSON.parse(cookie.affObject),
54
+ };
55
+
56
+ const res = await fetch(`${process.env.GATSBY_TRACKING_API_URL}?${new URLSearchParams(urlParam).toString()}`).catch(
16
57
  (err) => null
17
58
  );
18
59