sfc-utils 1.4.145 → 1.4.147

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.
@@ -2,6 +2,8 @@ import { getBlueconic } from "../../blueconic";
2
2
  import { getBrands3 } from "../../brands3";
3
3
  import { appCheck, blendHDN } from "../../index";
4
4
 
5
+ const currentEnv = process.env.GATSBY_DEPLOY_ENV;
6
+
5
7
  /** Used for resizing the WCM Image */
6
8
  function debounce(fn, ms) {
7
9
  let timer;
@@ -14,7 +16,7 @@ function debounce(fn, ms) {
14
16
  };
15
17
  }
16
18
 
17
- function appendLayoutScripts(isEmbedded, isAdRemoved, marketKey) {
19
+ function appendLayoutScripts(isEmbedded, isAdRemoved, marketKey, category) {
18
20
  const isApp = appCheck();
19
21
 
20
22
  // React Helmet is actually terrible and runs these scripts twice, so we are including them async ourselves
@@ -38,11 +40,61 @@ function appendLayoutScripts(isEmbedded, isAdRemoved, marketKey) {
38
40
  }
39
41
 
40
42
  if (!isEmbedded && !isAdRemoved) {
41
- let script = document.createElement("script");
42
- script.type = "text/javascript";
43
- script.id = "adPositionManagerScriptTag";
44
- script.src = "https://aps.hearstnp.com/Scripts/loadAds.js";
45
- document.body.appendChild(script);
43
+ // If category is passed, that means we're supporting HTL
44
+ if (category) {
45
+ // Set ad params
46
+ if (typeof window.HDN !== "undefined") {
47
+ window.HDN.dataLayer.visit = window.HDN.dataLayer.visit || {};
48
+ window.HDN.dataLayer.visit.urlHash = window.location.hash;
49
+ }
50
+ // Get the domain off the URL
51
+ const domain = window.location.origin;
52
+ const fullURL = window.location.href;
53
+ const shortDomain = domain.replace("https://www.", "");
54
+ const script = document.createElement("script");
55
+ // Try to get the htlbid URL to see if it's enabled
56
+ script.type = "text/javascript";
57
+ script.src = `https://htlbid.com/v3/${shortDomain}/hnpbid.js`;
58
+ document.body.appendChild(script);
59
+ // Add stylesheet
60
+ const link = document.createElement("link");
61
+ link.rel = "stylesheet";
62
+ link.href = `https://htlbid.com/v3/${shortDomain}/hnpbid.css`;
63
+ document.head.appendChild(link);
64
+ // Add vars
65
+ if (window.hnpbid) {
66
+ console.log("hnpbid exists");
67
+ window.hnpbid = window.hnpbid || {};
68
+ window.hnpbid.cmd = window.hnpbid.cmd || [];
69
+ window.hnpbid.cmd.push(() => {
70
+ window.hnpbid.setTargeting(
71
+ "is_testing",
72
+ currentEnv === "production" ? "no" : "yes"
73
+ ); // Set to "no" for production
74
+ window.hnpbid.setTargeting("is_home", "no"); // Set to "yes" on the homepage
75
+ window.hnpbid.setTargeting("post_id", `${fullURL}`);
76
+ window.hnpbid.setTargeting("category", category || "news");
77
+ // init
78
+ window.hnpbid.layout();
79
+ });
80
+ } else {
81
+ console.log("hnpbid does not exist");
82
+ // If global var was not defined, start Juice
83
+ let script = document.createElement("script");
84
+ script.type = "text/javascript";
85
+ script.id = "adPositionManagerScriptTag";
86
+ script.src = "https://aps.hearstnp.com/Scripts/loadAds.js";
87
+ document.body.appendChild(script);
88
+ }
89
+ } else {
90
+ console.log("juice fallback");
91
+ // If no category, this is the old version and we're supporting Juice (expires in Nov 2024)
92
+ let script = document.createElement("script");
93
+ script.type = "text/javascript";
94
+ script.id = "adPositionManagerScriptTag";
95
+ script.src = "https://aps.hearstnp.com/Scripts/loadAds.js";
96
+ document.body.appendChild(script);
97
+ }
46
98
  }
47
99
 
48
100
  // Wait a beat, then add to body so it doesn't mess with the head (which Helmet seems to want to manage)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfc-utils",
3
- "version": "1.4.145",
3
+ "version": "1.4.147",
4
4
  "author": "ewagstaff <evanjwagstaff@gmail.com>",
5
5
  "dependencies": {
6
6
  "archieml": "^0.4.2",