siteMapPerso

refactor

11/13/2023 4:21:32 PM

Changes

mySiteMap.js 235(+125 -110)

Details

mySiteMap.js 235(+125 -110)

diff --git a/mySiteMap.js b/mySiteMap.js
index 47b6a50..239a752 100644
--- a/mySiteMap.js
+++ b/mySiteMap.js
@@ -1,6 +1,6 @@
 
 
-const enviroment = 'https://dev.';
+const enviroment = 'https://qa.';
 //DATOS DE USUARIO
 const email = vsm.session.email != "" ? vsm.session.email : "";
 const idUser = vsm.session.id != "" ? vsm.session.id : "";
@@ -11,81 +11,123 @@ dateTime = `${dateTime.getDate()}/${dateTime.getMonth()}/${dateTime.getFullYear(
 
 let isMatch = false
 let url = ""
-//SELECTORES y zonas Genericos
 
+
+
+//SELECTORES y zonas Genericos
 let globalZones = [
     { name: "Header", selector: '#page-header' },
     { name: "Footer", selector: '#page-footer' },
 ]
 
+
 let globalListeners = [
-    '#page-header-session-box .sign-in-button',
-    `#page-header-middle .b-suscription`,
-    `.svg-icon.menu`,
-    `.session.with-avatar`,
-    `.session-options li:nth-child(2) a`,
-    `#main-menu ul li a`,
-    ".piece.markets.standard ul li"
+    { class: "#page-header-session-box .sign-in-button", labelName: 'Botón Ingresar' },
+    { class: "#page-header-middle .b-suscription", labelName: 'Botón Suscribite' },
+    { class: ".svg-icon.menu", labelName: 'Botón MENU sitio' },
+    { class: ".session.with-avatar", labelName: 'Botón MENU mi perfil' },
+    { class: ".session-options li:nth-child(2) a", labelName: 'Botón MI PERFIL' },
+    { class: "#main-menu ul li a", labelName: 'TAGS' },
+    { class: ".piece.markets.standard ul li", labelName: 'TICKERS' },
 ]
 //
 
 //SELECTORES y zonas Home
 let homeListeners = [
-    `.section article.item`,
-    `.sectionfull article.item`,
-    `article.locked`,
-    `.columnists .items article.item`
+    { class: `.section article.item`, labelName: '' },
+    { class: `.sectionfull article.item`, labelName: '' },
+    { class: `article.locked`, labelName: 'Article Member from Home' },
+    { class: `.columnists .items article.item`, labelName: 'Clumnists from Home' },
 ]
 
+let payWallListeners = [`.item .button`, `.item .list_items`, `.otros-planes__item a`, `.footer-footer a`]
+
 let homeInteractions = {
     name: "Home"
 }
-//
-function ReadHomeBlocks(target) {
-    let main = document.querySelector('.main-container');
-    let block1 = main.childNodes[0].querySelectorAll('article.item');
-    let block2 = main.childNodes[2].querySelectorAll('article.item')
-    sendDataFromHomeBlocks("Click, Article from home (Bloque1)", target, block1)
-    sendDataFromHomeBlocks("Click, Article from home (Bloque2)", target, block2)
-}
 
-function ReadGlobalEvents(event) {
-    let dataName = SalesforceInteractions.cashDom(event.target).text()
-    let compareClass = "." + event.currentTarget.classList.value.replace(/\s+/g, '.')
+const home = new PageType("Home", "cronista.com", homeInteractions, homeListeners);
+const payWall = new PageType("PayWall", `cronista.com/suscripciones/`, homeInteractions, payWallListeners);
 
-    if (event.target.innerText == "Mi perfil") {
-        dataName = "Botón Mi perfil"
-    }
+function Pages() {
+    return [home, payWall]
+}
+//
 
-    if (compareClass == globalListeners[3]) {
-        dataName = "Click Botón Desplegable MENU perfil"
-    }
+SalesforceInteractions.init({
+    cookieDomain: "cronista.com",
+}).then(() => {
+    const sitemapConfig = {
+        global: {
+            onActionEvent: (actionEvent) => {
+                url = window.location.href
+                if (email) {
+                    actionEvent.user = actionEvent.user || {};
+                    actionEvent.user.attributes = actionEvent.user.attributes || {};
+                    actionEvent.user.identities = actionEvent.user.identities || {};
+                    actionEvent.user.attributes.URL || {};
+                    actionEvent.user.attributes.contentZones || {};
+                    actionEvent.user.attributes.emailAddress = email;
+                    actionEvent.user.attributes.isSuscription = isSuscriber;
+                    actionEvent.user.attributes.name = userName;
+                    actionEvent.user.attributes.lastName = userName;
+                    actionEvent.user.attributes.date = dateTime
+                    actionEvent.user.identities.userIdCms = idUser;
+                }
+                return actionEvent;
+            },
+            contentZones: GenerateContentZones(globalZones),
+            listeners: GenerateListeners("Global", globalListeners),
+        },
+        pageTypeDefault: {
+            name: "default",
+            interaction: {
+                name: "Default Page",
+            }
+        },
+        pageTypes: Pages()
+    };
+    SalesforceInteractions.initSitemap(sitemapConfig);
+});
 
-    if (compareClass == globalListeners[2]) {
-        dataName = "MENU sitio"
-    }
+function PageType(name, myUrl, interaction, myEvents) {
+    this.name = name;
+    this.interaction = interaction;
+    this.isMatch = () => {
+        let url = window.location.href;
+        if (url.includes('?') || url.includes('/')) {
+            url = url.slice(0, window.location.href.lastIndexOf('?'));
+        }
+        console.log(`${enviroment}${myUrl}`)
+        isMatch = (url === `${enviroment}${myUrl}` ? true : false);
+        console.log(isMatch)
+        if (name == "PayWall") {
+            let limit = new URL(window.location.href).searchParams.get("limit")
+            console.log(limit)
+        }
 
 
-    SalesforceInteractions.sendEvent({
-        interaction: {
-            name: dataName,
-            attributes: {
-                userIdCms: idUser,
-                name: userName,
-                lastName: userName,
-                isSuscriber: isSuscriber,
-                emailAddress: email,
-                continueUrl: url
-            },
-        },
-    });
+        return isMatch;
+    };
+    this.listeners = GenerateListeners(name, myEvents);
+}
 
+function ReadHomeBlocks(event) {
+    let main = document.querySelector('.main-container');
+    let block1 = main.childNodes[0].querySelectorAll('article.item');
+    let block2 = main.childNodes[2].querySelectorAll('article.item')
+    sendDataFromHomeBlocks("Click, Article from home (Bloque1)", event, block1)
+    sendDataFromHomeBlocks("Click, Article from home (Bloque2)", event, block2)
 }
 
 function sendDataFromHomeBlocks(nameEvent, target, container) {
-    for (let i = 0; i < container.length; i++) {
 
+    for (let i = 0; i < container.length; i++) {
+        console.log(nameEvent)
+        console.log(target)
+        console.log(container)
         if (target === container[i]) {
+            console.log("cumple")
             SalesforceInteractions.sendEvent({
                 interaction: {
                     name: nameEvent,
@@ -106,6 +148,31 @@ function sendDataFromHomeBlocks(nameEvent, target, container) {
 
 }
 
+function ReadGlobalEvents(event, listeners) {
+    let dataName = listeners.labelName
+
+    if (listeners.labelName == "TICKERS" || listeners.labelName == "TAGS") {
+        dataName = listeners.labelName + ": " + SalesforceInteractions.cashDom(event.target).text()
+    }
+
+    SalesforceInteractions.sendEvent({
+        interaction: {
+            name: dataName,
+            attributes: {
+                userIdCms: idUser,
+                name: userName,
+                lastName: userName,
+                isSuscriber: isSuscriber,
+                emailAddress: email,
+                continueUrl: url
+            },
+        },
+    });
+
+}
+
+
+
 function GenerateContentZones(zones) {
 
     let ContentZones = [];
@@ -126,15 +193,20 @@ function GenerateListeners(pageType, elements) {
 
     if (elements.length > 0) {
         for (let i = 0; i < elements.length; i++) {
-            if (pageType == "Home" && (elements[i] == elements[0] || elements[i] == elements[1])) {
-                let myEventsBlock = SalesforceInteractions.listener("click", elements[i], (e) => {
-                    ReadHomeBlocks(e)
+
+            if (pageType == "Home" && (elements[i].class == elements[0].class || elements[i].class == elements[1].class)) {
+                console.log(elements[i].class)
+                let myEventsBlock = SalesforceInteractions.listener("click", elements[i].class, (e) => {
+                    e.preventDefault()
+                    console.log(e)
+                    ReadHomeBlocks(e.currentTarget)
                 })
                 listeners.push(myEventsBlock)
             } else {
-                let myEvents = SalesforceInteractions.listener("click", `${elements[i]}`, (e) => {
+                let myEvents = SalesforceInteractions.listener("click", `${elements[i].class}`, (e) => {
                     e.preventDefault()
-                    ReadGlobalEvents(e)
+                    console.log(elements[i].class)
+                    ReadGlobalEvents(e, elements[i])
                     e.stopPropagation();
                 })
 
@@ -143,61 +215,4 @@ function GenerateListeners(pageType, elements) {
         }
     }
     return listeners;
-}
-
-function PageType(name, myUrl, interaction, myEvents) {
-    this.name = name;
-    this.interaction = interaction;
-    this.isMatch = () => {
-        let url = window.location.href;
-        if (url.includes('?') || url.includes('/')) {
-            url = url.slice(0, window.location.href.lastIndexOf('?'));
-        }
-        isMatch = (url === `${enviroment}${myUrl}` ? true : false);
-
-
-        return isMatch;
-    };
-    this.listeners = GenerateListeners("Home", myEvents);
-}
-const home = new PageType("Home", "cronista.com", homeInteractions, homeListeners);
-
-function Pages() {
-    return [home]
-}
-
-SalesforceInteractions.init({
-    cookieDomain: "cronista.com",
-}).then(() => {
-    const sitemapConfig = {
-        global: {
-            onActionEvent: (actionEvent) => {
-                url = window.location.href
-                if (email) {
-                    actionEvent.user = actionEvent.user || {};
-                    actionEvent.user.attributes = actionEvent.user.attributes || {};
-                    actionEvent.user.identities = actionEvent.user.identities || {};
-                    actionEvent.user.attributes.URL || {};
-                    actionEvent.user.attributes.contentZones || {};
-                    actionEvent.user.attributes.emailAddress = email;
-                    actionEvent.user.attributes.isSuscription = isSuscriber;
-                    actionEvent.user.attributes.name = userName;
-                    actionEvent.user.attributes.lastName = userName;
-                    actionEvent.user.attributes.date = dateTime
-                    actionEvent.user.identities.userIdCms = idUser;
-                }
-                return actionEvent;
-            },
-            contentZones: GenerateContentZones(globalZones),
-            listeners: GenerateListeners("Global", globalListeners),
-        },
-        pageTypeDefault: {
-            name: "default",
-            interaction: {
-                name: "Default Page",
-            }
-        },
-        pageTypes: Pages()
-    };
-    SalesforceInteractions.initSitemap(sitemapConfig);
-});
\ No newline at end of file
+}
\ No newline at end of file