gatsby-core-theme 30.0.25 → 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,13 @@
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
+
1
11
  ## [30.0.25](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v30.0.24...v30.0.25) (2023-11-29)
2
12
 
3
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-core-theme",
3
- "version": "30.0.25",
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(`page_type=${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}
@@ -173,10 +173,15 @@ Tracker.propTypes = {
173
173
  styles: PropTypes.shape({}),
174
174
  };
175
175
 
176
- export async function getServerData({ pageContext, url }) {
176
+ export async function getServerData({ pageContext, headers, url }) {
177
177
  let res = '';
178
-
179
- res = await getAffiliateLink(pageContext.operator, url, pageContext.page.path, pageContext.page);
178
+ res = await getAffiliateLink(
179
+ pageContext.operator,
180
+ url,
181
+ pageContext.page.path,
182
+ pageContext.page,
183
+ headers
184
+ );
180
185
  return res;
181
186
  }
182
187
 
@@ -29,28 +29,31 @@ export function getTrackerName(operator, page, path) {
29
29
  return { name: trackerName, value: tracker };
30
30
  }
31
31
 
32
-
32
+ /* eslint-disable no-return-assign */
33
33
  /* eslint-disable import/prefer-default-export */
34
- export async function getAffiliateLink(operator, url, path, page) {
35
- let urlParams = `site_id=${process.env.SITE_ID}&operator_short_name=${
36
- operator.short_name
37
- }&operator_type=${operator.type}&language=${operator.market.split('_')[1]}&market_short_code=${
38
- operator.market
39
- }`;
40
-
41
- const urlSplit = url.split('?');
42
-
43
- if (urlSplit.length === 2) {
44
- urlParams += `&${urlSplit[1]}`;
45
- }
46
-
34
+ export async function getAffiliateLink(operator, url, path, page, headers) {
47
35
  const trackerName = await getTrackerName(operator, page, path);
48
36
 
49
- if(trackerName.name !== 'main') {
50
- urlParams += `&tracker_name=${trackerName.name}`;
51
- }
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
+ };
52
55
 
53
- const res = await fetch(`${process.env.GATSBY_TRACKING_API_URL}?${urlParams}`).catch(
56
+ const res = await fetch(`${process.env.GATSBY_TRACKING_API_URL}?${new URLSearchParams(urlParam).toString()}`).catch(
54
57
  (err) => null
55
58
  );
56
59