sfc-utils 1.4.168 → 1.4.170

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/accountswap.js CHANGED
@@ -10,17 +10,19 @@ const pollForAccount = async function (i, isNav) {
10
10
  // Start the iterator
11
11
  if (!i) {
12
12
  i = 0;
13
- }
14
- // Add a click event to signin
15
- if (isNav) {
16
- const signinButton = document.querySelector(".hnp-signin");
17
- if (signinButton) {
18
- // Add event listener to signin button
19
- signinButton.onclick = function (e) {
20
- treg.realm.core.login();
21
- e.preventDefault();
22
- e.stopPropagation();
23
- };
13
+ // Add a click event to signin
14
+ if (isNav) {
15
+ const signinButton = document.querySelector(".hnp-signin");
16
+ if (signinButton) {
17
+ console.log("Found signin button");
18
+ // Add event listener to signin button
19
+ signinButton.onclick = function (e) {
20
+ console.log("Clicked signin button");
21
+ window.treg.realm.core.login();
22
+ e.preventDefault();
23
+ e.stopPropagation();
24
+ };
25
+ }
24
26
  }
25
27
  }
26
28
  // Safecheck for treg since it might not be global yet
@@ -1,4 +1,5 @@
1
1
  import React, { useRef, useState, useEffect } from "react";
2
+ import { trackEvent } from "./helpers/utilfunctions.mjs";
2
3
  import * as geocoderStyles from "../styles/modules/geocoder.module.less";
3
4
 
4
5
  // This is a singleton event listener that we can use to add/remove event listeners
@@ -23,9 +24,9 @@ const Geocoder = ({
23
24
  filterRegion, // You need to test results, but could also pass in a neighbourhood, district, city, county, state or administrative area
24
25
  market, // Will filter by the market's state if no filterRegion provided
25
26
  resultFunc,
26
- // buttonTrackingId, // To be used for analytics once system is more finalized
27
27
  placeholder,
28
28
  inputValueOverride, // Used to clear/change the input value from the parent component
29
+ buttonTrackingId = "SelectAnAddress", // A string sent as part of the onClick tracking event - can be used as an 'id' of sorts (e.g. "ScriptTool")
29
30
  }) => {
30
31
  // Show a loader when we're requesting
31
32
  const [loading, setLoading] = useState(false);
@@ -148,6 +149,7 @@ const Geocoder = ({
148
149
  if (resultFunc) {
149
150
  resultFunc(selectedLocation);
150
151
  }
152
+ trackEvent("Click", "Dropdown", "Geocoder", buttonTrackingId);
151
153
  }
152
154
  // Hide the list now
153
155
  setLocData(null);
@@ -227,6 +229,7 @@ const Geocoder = ({
227
229
  if (resultFunc) {
228
230
  resultFunc(locData[i]);
229
231
  }
232
+ trackEvent("Click", "Dropdown", "Geocoder", buttonTrackingId);
230
233
  }}
231
234
  >
232
235
  <button
@@ -202,12 +202,11 @@ function trackEvent(
202
202
  elementContent = null,
203
203
  elementText = null
204
204
  ) {
205
+ // all of these variables are used regardless of if it's an embed
205
206
  const storySettings = getSettings();
206
207
  const systemSettingsObj = systemSettings[0];
207
208
  const elementVariant = `${systemSettingsObj.Repo}|${systemSettingsObj.Project_Type}`;
208
209
  const linkUrl = `${storySettings.PROJECT.SUBFOLDER}/${storySettings.PROJECT.SLUG}`;
209
- const urlHash = window.HDN.dataLayer.visit.urlHash;
210
-
211
210
  let event;
212
211
  if (eventType === "Click") {
213
212
  event = "hnp_click";
@@ -215,70 +214,47 @@ function trackEvent(
215
214
  event = "hnp_impression";
216
215
  }
217
216
 
218
- window.dataLayer.push({
219
- event: event, //REQUIRED; Fixed value
220
- element_name: elementName, //REQUIRED; One of a list of tags/types of elements on the page (e.g. Button, Map, Tooltip, ToggleButton, Dropdown). TO DO: create a consistent list of this
221
- element_content: elementContent, //REQUIRED; One of a list of subtypes of element types (e.g. Button) on the page (e.g. Geocoder, Searchbar, Prev/Next). TO DO: create a consistent list of this, maybe
222
- element_variant: elementVariant, //REQUIRED; Template type (e.g. custom-repo-name|gatsby) (top-list|plat)
223
- element_text: elementText, //REQUIRED; What was the actual text or alt-text of the thing that was clicked (InnerHTML or id specific to that element)
224
- component_type: null, //OPTIONAL; If BC components uses Storybook components: Organism or molecule from storybook (whatever the highest level component from storybook that the clicked on item belongs to)
225
- component_subtype: null, //OPTIONAL; If BC components uses Storybook components: Variant of the component_type from storybook
226
- component_detail: null, //OPTIONAL; If BC components uses Storybook components: WCM TITLE|Position|Atom from storybook. This pipe-delimited structure is required. When values are not available for a given position, leave the position blank so the order of information doesn't change. e.g. something|| or something||something_else
227
- zone: null, // OPTIONAL; For WCM components. The WCM zone the component was displayed in.
228
- link_url: linkUrl, //REQUIRED; What is the slug of the project?
229
- url_hash: urlHash, // REQUIRED;
230
- outbound: false, //REQUIRED; Boolean indicating whether the link that was clicked took the user to a different domain.
231
- source_system: "devhub", //REQUIRED; What platform powered the element? One of cookie, blueconic, realm, castle, devhub, treg, legacy obits, sailthru, casper, wordpress, hnp-jwplayer, event_data_service (other options required discussion with BI/DE)
232
- });
233
- }
234
-
235
- const trackEmbedEvent = (
236
- eventType,
237
- elementName = null,
238
- elementContent = null,
239
- elementText = null
240
- ) => {
241
- const storySettings = getSettings();
242
- const systemSettingsObj = systemSettings[0];
243
- const elementVariant = `${systemSettingsObj.Repo}|${systemSettingsObj.Project_Type}`;
244
- const linkUrl = `${storySettings.Year}/${storySettings.Slug}`;
245
-
246
- let event;
247
- if (eventType === "Click") {
248
- event = "hnp_click";
249
- } else if (eventType === "Impression") {
250
- event = "hnp_impression";
251
- }
217
+ if (window.dataLayer) {
218
+ // this is NOT an embed, so push to the dataLayer
219
+ const urlHash = window.HDN.dataLayer.visit.urlHash;
252
220
 
253
- var embed_event = {
254
- event: event, //REQUIRED; Fixed value
255
- element_name: elementName, //REQUIRED; One of a list of tags/types of elements on the page (e.g. Button, Map, Tooltip, ToggleButton, Dropdown). TO DO: create a consistent list of this
256
- element_content: elementContent, //REQUIRED; One of a list of subtypes of element types (e.g. Button) on the page (e.g. Geocoder, Searchbar, Prev/Next). TO DO: create a consistent list of this, maybe
257
- element_variant: elementVariant, //REQUIRED; Template type (e.g. custom-repo-name|gatsby) (top-list|plat)
258
- element_text: elementText, //REQUIRED; What was the actual text or alt-text of the thing that was clicked (InnerHTML or id specific to that element)
259
- component_type: null, //OPTIONAL; If BC components uses Storybook components: Organism or molecule from storybook (whatever the highest level component from storybook that the clicked on item belongs to)
260
- component_subtype: null, //OPTIONAL; If BC components uses Storybook components: Variant of the component_type from storybook
261
- component_detail: null, //OPTIONAL; If BC components uses Storybook components: WCM TITLE|Position|Atom from storybook. This pipe-delimited structure is required. When values are not available for a given position, leave the position blank so the order of information doesn't change. e.g. something|| or something||something_else
262
- zone: null, // OPTIONAL; For WCM components. The WCM zone the component was displayed in.
263
- link_url: linkUrl, //REQUIRED; What is the slug of the project?
264
- outbound: false, //REQUIRED; Boolean indicating whether the link that was clicked took the user to a different domain.
265
- source_system: "devhub", //REQUIRED; What platform powered the element? One of cookie, blueconic, realm, castle, devhub, treg, legacy obits, sailthru, casper, wordpress, hnp-jwplayer, event_data_service (other options required discussion with BI/DE)
266
- iframe_event: true,
267
- };
221
+ window.dataLayer.push({
222
+ event: event, //REQUIRED; Fixed value
223
+ element_name: elementName, //REQUIRED; One of a list of tags/types of elements on the page (e.g. Button, Map, Tooltip, ToggleButton, Dropdown). TO DO: create a consistent list of this
224
+ element_content: elementContent, //REQUIRED; One of a list of subtypes of element types (e.g. Button) on the page (e.g. Geocoder, Searchbar, Prev/Next). TO DO: create a consistent list of this, maybe
225
+ element_variant: elementVariant, //REQUIRED; Template type (e.g. custom-repo-name|gatsby) (top-list|plat)
226
+ element_text: elementText, //REQUIRED; What was the actual text or alt-text of the thing that was clicked (InnerHTML or id specific to that element)
227
+ component_type: null, //OPTIONAL; If BC components uses Storybook components: Organism or molecule from storybook (whatever the highest level component from storybook that the clicked on item belongs to)
228
+ component_subtype: null, //OPTIONAL; If BC components uses Storybook components: Variant of the component_type from storybook
229
+ component_detail: null, //OPTIONAL; If BC components uses Storybook components: WCM TITLE|Position|Atom from storybook. This pipe-delimited structure is required. When values are not available for a given position, leave the position blank so the order of information doesn't change. e.g. something|| or something||something_else
230
+ zone: null, // OPTIONAL; For WCM components. The WCM zone the component was displayed in.
231
+ link_url: linkUrl, //REQUIRED; What is the slug of the project?
232
+ url_hash: urlHash, // REQUIRED;
233
+ outbound: false, //REQUIRED; Boolean indicating whether the link that was clicked took the user to a different domain.
234
+ source_system: "devhub", //REQUIRED; What platform powered the element? One of cookie, blueconic, realm, castle, devhub, treg, legacy obits, sailthru, casper, wordpress, hnp-jwplayer, event_data_service (other options required discussion with BI/DE)
235
+ });
236
+ } else {
237
+ // this IS an embed, so use this special logic
238
+ var embed_event = {
239
+ event: event, //REQUIRED; Fixed value
240
+ element_name: elementName, //REQUIRED; One of a list of tags/types of elements on the page (e.g. Button, Map, Tooltip, ToggleButton, Dropdown). TO DO: create a consistent list of this
241
+ element_content: elementContent, //REQUIRED; One of a list of subtypes of element types (e.g. Button) on the page (e.g. Geocoder, Searchbar, Prev/Next). TO DO: create a consistent list of this, maybe
242
+ element_variant: elementVariant, //REQUIRED; Template type (e.g. custom-repo-name|gatsby) (top-list|plat)
243
+ element_text: elementText, //REQUIRED; What was the actual text or alt-text of the thing that was clicked (InnerHTML or id specific to that element)
244
+ component_type: null, //OPTIONAL; If BC components uses Storybook components: Organism or molecule from storybook (whatever the highest level component from storybook that the clicked on item belongs to)
245
+ component_subtype: null, //OPTIONAL; If BC components uses Storybook components: Variant of the component_type from storybook
246
+ component_detail: null, //OPTIONAL; If BC components uses Storybook components: WCM TITLE|Position|Atom from storybook. This pipe-delimited structure is required. When values are not available for a given position, leave the position blank so the order of information doesn't change. e.g. something|| or something||something_else
247
+ zone: null, // OPTIONAL; For WCM components. The WCM zone the component was displayed in.
248
+ link_url: linkUrl, //REQUIRED; What is the slug of the project?
249
+ outbound: false, //REQUIRED; Boolean indicating whether the link that was clicked took the user to a different domain.
250
+ source_system: "devhub", //REQUIRED; What platform powered the element? One of cookie, blueconic, realm, castle, devhub, treg, legacy obits, sailthru, casper, wordpress, hnp-jwplayer, event_data_service (other options required discussion with BI/DE)
251
+ iframe_event: true,
252
+ };
268
253
 
269
- if (typeof window !== "undefined") {
270
- window.parent.postMessage(embed_event, "*"); // Sends event to parent page
254
+ if (typeof window !== "undefined") {
255
+ window.parent.postMessage(embed_event, "*"); // Sends event to parent page
256
+ }
271
257
  }
258
+ }
272
259
 
273
- //TO TEST: I think this needs to go directly into the iframe embed code?
274
- //window.addEventListener("message", (message) => {if (message.data.iframe_event) {var event = message.data;dataLayer.push(event);}});
275
- };
276
-
277
- export {
278
- debounce,
279
- appendLayoutScripts,
280
- formatHDN,
281
- getFigureWidth,
282
- trackEvent,
283
- trackEmbedEvent,
284
- };
260
+ export { debounce, appendLayoutScripts, formatHDN, getFigureWidth, trackEvent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfc-utils",
3
- "version": "1.4.168",
3
+ "version": "1.4.170",
4
4
  "author": "ewagstaff <evanjwagstaff@gmail.com>",
5
5
  "dependencies": {
6
6
  "archieml": "^0.4.2",