From fda9f7666834489d0ac446c588677106376e20e4 Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Wed, 1 Dec 2021 18:07:18 +0530 Subject: [PATCH 1/5] Initial commit for PostAffiliatePro --- integrations/PostAffiliatePro/browser.js | 151 +++++++++++++++++++++++ integrations/PostAffiliatePro/index.js | 3 + integrations/PostAffiliatePro/util.js | 10 ++ integrations/client_server_name.js | 1 + integrations/index.js | 3 +- integrations/integration_cname.js | 4 + 6 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 integrations/PostAffiliatePro/browser.js create mode 100644 integrations/PostAffiliatePro/index.js create mode 100644 integrations/PostAffiliatePro/util.js diff --git a/integrations/PostAffiliatePro/browser.js b/integrations/PostAffiliatePro/browser.js new file mode 100644 index 0000000000..4e943680e7 --- /dev/null +++ b/integrations/PostAffiliatePro/browser.js @@ -0,0 +1,151 @@ +/* eslint-disable class-methods-use-this */ +/* eslint-disable no-underscore-dangle */ +import get from "get-value"; +import logger from "../../utils/logUtil"; +import ScriptLoader from "./util"; + +class PostAffiliatePro { + constructor(config) { + this.name = "POSTAFFILIATEPRO"; + this.url = config.url; + this.mergeProducts = config.mergeProducts; + this.accountId = config.accountId; + this.affLinkId = config.affLinkId; + this.idName = config.idName; + this.cookieLinkId = config.cookieLinkId; + this.cookieName = config.cookieName; + this.affiliateToCustomField = config.affiliateToCustomField; + this.campaignToCustomField = config.campaignToCustomField; + this.cookieDomain = config.cookieDomain; + this.cookieToCustomField = config.cookieToCustomField; + this.disableTrackingMethod = config.disableTrackingMethod; + this.paramNameUserId = config.paramNameUserId; + this.clickEvents = config.clickEvents; + } + + init() { + logger.debug("===in init Post Affiliate Pro==="); + if (!this.url) { + logger.debug("URL is missing"); + return; + } + ScriptLoader(this.url); + } + + isLoaded() { + logger.debug("===In isLoaded Post Affiliate Pro==="); + return !!window.PostAffTracker; + } + + isReady() { + logger.debug("===In isReady Post Affiliate Pro==="); + + if (window.PostAffTracker) { + if (!this.disableTrackingMethod) + window.PostAffTracker.disableTrackingMethod("F"); + if (this.paramNameUserId) + window.PostAffTracker.setParamNameUserId(this.paramNameUserId); + if (this.accountId) window.PostAffTracker.setAccountId(this.accountId); + if (this.cookieDomain) + window.PostAffTracker.setCookieDomain(this.cookieDomain); + if (this.cookieToCustomField) + window.PostAffTracker.writeCookieToCustomField( + this.cookieToCustomField + ); + if (this.affiliateToCustomField) + window.PostAffTracker.writeAffiliateToCustomField( + this.affiliateToCustomField + ); + if (this.campaignToCustomField) + window.PostAffTracker.writeCampaignToCustomField( + this.campaignToCustomField + ); + if (this.affLinkId && this.idName) + window.PostAffTracker.writeAffiliateToLink(this.affLinkId, this.idName); + if (this.cookieName && this.cookieLinkId) + window.PostAffTracker.writeCookieToLink( + this.cookieLinkId, + this.cookieName + ); + return true; + } + return false; + } + + identify(rudderElement) { + logger.debug("===In Post Affiliate Pro identify==="); + const { message } = rudderElement; + const visitorId = get(message, "userId"); + window.PostAffTracker.setVisitorId(visitorId); + } + // eslint-disable-next-line lines-between-class-members + track(rudderElement) { + logger.debug("===In Post Affiliate Pro track==="); + const clickEventsArr = this.clickEvents + ? this.clickEvents.split(",") + : null; + const { message } = rudderElement; + const { event } = message; + const { properties } = message; + if (clickEventsArr && clickEventsArr.includes(event)) { + if (properties) { + if (properties.data1) window.Data1 = properties.data1; + if (properties.data2) window.Data2 = properties.data2; + if (properties.affiliateId) window.AffiliateID = properties.affiliateId; + if (properties.bannerId) window.BannerID = properties.bannerId; + if (properties.campaignId) window.CampaignID = properties.campaignId; + if (properties.channel) window.Channel = properties.channel; + } + window.PostAffTracker.track(); + } + if (event === "Order Completed") { + const productsArr = + properties && properties.products ? properties.products : null; + if (!productsArr) { + logger.debug( + "===Required properties and products for Order Completed event." + ); + return; + } + + /* if mergeProduct is enabled we will merge the products */ + + if (this.mergeProducts) { + window.sale = window.PostAffTracker.createSale(); + if (properties.total) window.sale.setTotalCost(properties.total); + if (properties.fixedCost) + window.sale.setFixedCost(properties.fixedCost); + if (properties.order_id) window.sale.setOrderID(properties.order_id); + if (properties.data1) window.sale.setData1(properties.data1); + if (properties.data2) window.sale.setData2(properties.data2); + if (properties.data3) window.sale.setData3(properties.data3); + if (properties.data4) window.sale.setData4(properties.data4); + if (properties.data5) window.sale.setData5(properties.data5); + if ( + properties.doNotDeleteCookies && + properties.doNotDeleteCookies === true + ) + window.sale.doNotDeleteCookies(); + if (properties.status) window.sale.setStatus(properties.status); + if (properties.currency) window.sale.setCurrency(properties.currency); + if (properties.customCommision) + window.sale.setCustomCommission(properties.customCommision); + if (properties.channel) window.sale.setChannelID(properties.channel); + if (properties.coupon) window.sale.setCoupon(properties.coupon); + if (properties.campaignId) + window.sale.setCampaignID(properties.campaignId); + if (properties.affiliateId) + window.sale.setAffiliateID(properties.affiliateId); + const mergedProductId = []; + for (let i = 0; i < productsArr.length; i += 1) + mergedProductId.push(productsArr[i].product_id); + const merged = mergedProductId.join(); + window.sale.setProductID(merged); + window.PostAffTracker.register(); + } else { + logger.debug("===TO DO==="); + } + } + } +} +export default PostAffiliatePro; diff --git a/integrations/PostAffiliatePro/index.js b/integrations/PostAffiliatePro/index.js new file mode 100644 index 0000000000..62ff5b4d86 --- /dev/null +++ b/integrations/PostAffiliatePro/index.js @@ -0,0 +1,3 @@ +import PostAffiliatePro from "./browser"; + +export default PostAffiliatePro; diff --git a/integrations/PostAffiliatePro/util.js b/integrations/PostAffiliatePro/util.js new file mode 100644 index 0000000000..98fa081ca1 --- /dev/null +++ b/integrations/PostAffiliatePro/util.js @@ -0,0 +1,10 @@ +const ScriptLoader = (url) => { + const js = document.createElement("script"); + js.src = url; + js.id = "pap_x2s6df8d"; + js.type = "text/javascript"; + const e = document.getElementsByTagName("script")[0]; + e.parentNode.insertBefore(js, e); +}; + +export default ScriptLoader; diff --git a/integrations/client_server_name.js b/integrations/client_server_name.js index d864137527..0d3fc7c479 100644 --- a/integrations/client_server_name.js +++ b/integrations/client_server_name.js @@ -41,6 +41,7 @@ const clientToServerNames = { MP: "Mixpanel", QUALTRICS: "Qualtrics", SENTRY: "Sentry", + POSTAFFILIATEPRO: "PostAffiliatePro", }; export { clientToServerNames }; diff --git a/integrations/index.js b/integrations/index.js index d24910c93e..da8494345d 100644 --- a/integrations/index.js +++ b/integrations/index.js @@ -40,7 +40,7 @@ import * as Sentry from "./Sentry"; import * as SnapPixel from "./SnapPixel"; import * as TVSquared from "./TVSquared"; import * as VWO from "./VWO"; - +import * as PostAffiliatePro from "./PostAffiliatePro"; // the key names should match the destination.name value to keep partity everywhere // (config-plan name, native destination.name , exported integration name(this one below)) @@ -87,6 +87,7 @@ const integrations = { SNAP_PIXEL: SnapPixel.default, TVSQUARED: TVSquared.default, VWO: VWO.default, + POSTAFFILIATEPRO: PostAffiliatePro.default, }; export { integrations }; diff --git a/integrations/integration_cname.js b/integrations/integration_cname.js index e812b00ef5..3c5ead5e64 100644 --- a/integrations/integration_cname.js +++ b/integrations/integration_cname.js @@ -124,6 +124,10 @@ const commonNames = { quantumMetric: "QUANTUMMETRIC", quantummetric: "QUANTUMMETRIC", Quantum_Metric: "QUANTUMMETRIC", + PostAffiliatePro: "POSTAFFILIATEPRO", + Post_ffiliate_pro: "POSTAFFILIATEPRO", + POST_AFFILIATE_PRO: "POSTAFFILIATEPRO", + postaffiliatepro: "POSTAFFILIATEPRO", }; export { commonNames }; From ed91f4b653832758477c9e30879bde85c50c1751 Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Thu, 2 Dec 2021 16:23:53 +0530 Subject: [PATCH 2/5] Commit for PostAffiliatePro --- integrations/PostAffiliatePro/browser.js | 71 +++++++++--------------- integrations/PostAffiliatePro/util.js | 10 ---- integrations/PostAffiliatePro/utils.js | 22 ++++++++ integrations/index.js | 1 - integrations/integration_cname.js | 3 +- 5 files changed, 51 insertions(+), 56 deletions(-) delete mode 100644 integrations/PostAffiliatePro/util.js create mode 100644 integrations/PostAffiliatePro/utils.js diff --git a/integrations/PostAffiliatePro/browser.js b/integrations/PostAffiliatePro/browser.js index 4e943680e7..9a722cf00e 100644 --- a/integrations/PostAffiliatePro/browser.js +++ b/integrations/PostAffiliatePro/browser.js @@ -1,8 +1,9 @@ /* eslint-disable class-methods-use-this */ /* eslint-disable no-underscore-dangle */ import get from "get-value"; +import updateSaleObject from "./utils"; +import ScriptLoader from "../ScriptLoader"; import logger from "../../utils/logUtil"; -import ScriptLoader from "./util"; class PostAffiliatePro { constructor(config) { @@ -29,7 +30,7 @@ class PostAffiliatePro { logger.debug("URL is missing"); return; } - ScriptLoader(this.url); + ScriptLoader("pap_x2s6df8d", this.url); } isLoaded() { @@ -101,51 +102,33 @@ class PostAffiliatePro { if (event === "Order Completed") { const productsArr = properties && properties.products ? properties.products : null; - if (!productsArr) { - logger.debug( - "===Required properties and products for Order Completed event." - ); - return; - } - - /* if mergeProduct is enabled we will merge the products */ - - if (this.mergeProducts) { - window.sale = window.PostAffTracker.createSale(); - if (properties.total) window.sale.setTotalCost(properties.total); - if (properties.fixedCost) - window.sale.setFixedCost(properties.fixedCost); - if (properties.order_id) window.sale.setOrderID(properties.order_id); - if (properties.data1) window.sale.setData1(properties.data1); - if (properties.data2) window.sale.setData2(properties.data2); - if (properties.data3) window.sale.setData3(properties.data3); - if (properties.data4) window.sale.setData4(properties.data4); - if (properties.data5) window.sale.setData5(properties.data5); - if ( - properties.doNotDeleteCookies && - properties.doNotDeleteCookies === true - ) - window.sale.doNotDeleteCookies(); - if (properties.status) window.sale.setStatus(properties.status); - if (properties.currency) window.sale.setCurrency(properties.currency); - if (properties.customCommision) - window.sale.setCustomCommission(properties.customCommision); - if (properties.channel) window.sale.setChannelID(properties.channel); - if (properties.coupon) window.sale.setCoupon(properties.coupon); - if (properties.campaignId) - window.sale.setCampaignID(properties.campaignId); - if (properties.affiliateId) - window.sale.setAffiliateID(properties.affiliateId); - const mergedProductId = []; - for (let i = 0; i < productsArr.length; i += 1) - mergedProductId.push(productsArr[i].product_id); - const merged = mergedProductId.join(); - window.sale.setProductID(merged); - window.PostAffTracker.register(); + if (productsArr) { + if (this.mergeProducts) { + window.sale = window.PostAffTracker.createSale(); + if (window.sale) updateSaleObject(window.sale, properties); + const mergedProductId = []; + for (let i = 0; i < productsArr.length; i += 1) + if (productsArr[i].product_id) + mergedProductId.push(productsArr[i].product_id); + const merged = mergedProductId.join(); + if (merged) window.sale.setProductID(merged); + } else { + for (let i = 0; i < productsArr.length; i += 1) { + window[`sale${i}`] = window.PostAffTracker.createSale(); + updateSaleObject(window[`sale${i}`], properties); + if (productsArr[i].product_id) + window[`sale${i}`].setProductID(productsArr[i].product_id); + } + } } else { - logger.debug("===TO DO==="); + window.sale = window.PostAffTracker.createSale(); } + window.PostAffTracker.register(); } } + + // reset() { + // window.PostAffTracker.setVisitorId(null); + // } } export default PostAffiliatePro; diff --git a/integrations/PostAffiliatePro/util.js b/integrations/PostAffiliatePro/util.js deleted file mode 100644 index 98fa081ca1..0000000000 --- a/integrations/PostAffiliatePro/util.js +++ /dev/null @@ -1,10 +0,0 @@ -const ScriptLoader = (url) => { - const js = document.createElement("script"); - js.src = url; - js.id = "pap_x2s6df8d"; - js.type = "text/javascript"; - const e = document.getElementsByTagName("script")[0]; - e.parentNode.insertBefore(js, e); -}; - -export default ScriptLoader; diff --git a/integrations/PostAffiliatePro/utils.js b/integrations/PostAffiliatePro/utils.js new file mode 100644 index 0000000000..047a6d4913 --- /dev/null +++ b/integrations/PostAffiliatePro/utils.js @@ -0,0 +1,22 @@ +// This function helps to populate the sale object +const updateSaleObject = (sale, properties) => { + if (properties.total) sale.setTotalCost(properties.total); + if (properties.fixedCost) sale.setFixedCost(properties.fixedCost); + if (properties.order_id) sale.setOrderID(properties.order_id); + if (properties.data1) sale.setData1(properties.data1); + if (properties.data2) sale.setData2(properties.data2); + if (properties.data3) sale.setData3(properties.data3); + if (properties.data4) sale.setData4(properties.data4); + if (properties.data5) sale.setData5(properties.data5); + if (properties.doNotDeleteCookies && properties.doNotDeleteCookies === true) + sale.doNotDeleteCookies(); + if (properties.status) sale.setStatus(properties.status); + if (properties.currency) sale.setCurrency(properties.currency); + if (properties.customCommision) + sale.setCustomCommission(properties.customCommision); + if (properties.channel) sale.setChannelID(properties.channel); + if (properties.coupon) sale.setCoupon(properties.coupon); + if (properties.campaignId) sale.setCampaignID(properties.campaignId); + if (properties.affiliateId) sale.setAffiliateID(properties.affiliateId); +}; +export default updateSaleObject; diff --git a/integrations/index.js b/integrations/index.js index da8494345d..a143f41aaa 100644 --- a/integrations/index.js +++ b/integrations/index.js @@ -43,7 +43,6 @@ import * as VWO from "./VWO"; import * as PostAffiliatePro from "./PostAffiliatePro"; // the key names should match the destination.name value to keep partity everywhere // (config-plan name, native destination.name , exported integration name(this one below)) - const integrations = { ADOBE_ANALYTICS: AdobeAnalytics.default, AM: Amplitude.default, diff --git a/integrations/integration_cname.js b/integrations/integration_cname.js index 3c5ead5e64..53f6a12ddf 100644 --- a/integrations/integration_cname.js +++ b/integrations/integration_cname.js @@ -125,9 +125,10 @@ const commonNames = { quantummetric: "QUANTUMMETRIC", Quantum_Metric: "QUANTUMMETRIC", PostAffiliatePro: "POSTAFFILIATEPRO", - Post_ffiliate_pro: "POSTAFFILIATEPRO", + Post_affiliate_pro: "POSTAFFILIATEPRO", POST_AFFILIATE_PRO: "POSTAFFILIATEPRO", postaffiliatepro: "POSTAFFILIATEPRO", + POSTAFFILIATEPRO: "POSTAFFILIATEPRO", }; export { commonNames }; From 8f5fbf535141ee256ff7d2414d06307b660b06e6 Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Thu, 2 Dec 2021 22:20:12 +0530 Subject: [PATCH 3/5] Commit for PostAffiliatePro --- integrations/PostAffiliatePro/browser.js | 2 +- integrations/client_server_name.js | 2 +- integrations/index.js | 2 +- integrations/integration_cname.js | 11 ++++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/integrations/PostAffiliatePro/browser.js b/integrations/PostAffiliatePro/browser.js index 9a722cf00e..d62625b24b 100644 --- a/integrations/PostAffiliatePro/browser.js +++ b/integrations/PostAffiliatePro/browser.js @@ -7,7 +7,7 @@ import logger from "../../utils/logUtil"; class PostAffiliatePro { constructor(config) { - this.name = "POSTAFFILIATEPRO"; + this.name = "POST_AFFILIATE_PRO"; this.url = config.url; this.mergeProducts = config.mergeProducts; this.accountId = config.accountId; diff --git a/integrations/client_server_name.js b/integrations/client_server_name.js index 0d3fc7c479..82c6488f9f 100644 --- a/integrations/client_server_name.js +++ b/integrations/client_server_name.js @@ -41,7 +41,7 @@ const clientToServerNames = { MP: "Mixpanel", QUALTRICS: "Qualtrics", SENTRY: "Sentry", - POSTAFFILIATEPRO: "PostAffiliatePro", + POST_AFFILIATE_PRO: "PostAffiliatePro", }; export { clientToServerNames }; diff --git a/integrations/index.js b/integrations/index.js index a143f41aaa..cd9d7e46a9 100644 --- a/integrations/index.js +++ b/integrations/index.js @@ -86,7 +86,7 @@ const integrations = { SNAP_PIXEL: SnapPixel.default, TVSQUARED: TVSquared.default, VWO: VWO.default, - POSTAFFILIATEPRO: PostAffiliatePro.default, + POST_AFFILIATE_PRO: PostAffiliatePro.default, }; export { integrations }; diff --git a/integrations/integration_cname.js b/integrations/integration_cname.js index 53f6a12ddf..266d0f740e 100644 --- a/integrations/integration_cname.js +++ b/integrations/integration_cname.js @@ -124,11 +124,12 @@ const commonNames = { quantumMetric: "QUANTUMMETRIC", quantummetric: "QUANTUMMETRIC", Quantum_Metric: "QUANTUMMETRIC", - PostAffiliatePro: "POSTAFFILIATEPRO", - Post_affiliate_pro: "POSTAFFILIATEPRO", - POST_AFFILIATE_PRO: "POSTAFFILIATEPRO", - postaffiliatepro: "POSTAFFILIATEPRO", - POSTAFFILIATEPRO: "POSTAFFILIATEPRO", + PostAffiliatePro: "POST_AFFILIATE_PRO", + Post_affiliate_pro: "POST_AFFILIATE_PRO", + "Post Affiliate Pro": "POST_AFFILIATE_PRO", + postaffiliatepro: "POST_AFFILIATE_PRO", + POSTAFFILIATEPRO: "POST_AFFILIATE_PRO", + POST_AFFILIATE_PRO: "POST_AFFILIATE_PRO", }; export { commonNames }; From 3ae7682bbf721584dc165f8270201de3d09cabac Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Fri, 3 Dec 2021 12:19:04 +0530 Subject: [PATCH 4/5] Commit for PostAffiliatePro --- integrations/PostAffiliatePro/browser.js | 3 +++ integrations/PostAffiliatePro/utils.js | 1 + 2 files changed, 4 insertions(+) diff --git a/integrations/PostAffiliatePro/browser.js b/integrations/PostAffiliatePro/browser.js index d62625b24b..db72cab61b 100644 --- a/integrations/PostAffiliatePro/browser.js +++ b/integrations/PostAffiliatePro/browser.js @@ -88,6 +88,7 @@ class PostAffiliatePro { const { message } = rudderElement; const { event } = message; const { properties } = message; + // We are going to call click event, for the events given in dashboard only. if (clickEventsArr && clickEventsArr.includes(event)) { if (properties) { if (properties.data1) window.Data1 = properties.data1; @@ -99,6 +100,7 @@ class PostAffiliatePro { } window.PostAffTracker.track(); } + // We are supporting only one event for sale. if (event === "Order Completed") { const productsArr = properties && properties.products ? properties.products : null; @@ -121,6 +123,7 @@ class PostAffiliatePro { } } } else { + // If any product is not available. window.sale = window.PostAffTracker.createSale(); } window.PostAffTracker.register(); diff --git a/integrations/PostAffiliatePro/utils.js b/integrations/PostAffiliatePro/utils.js index 047a6d4913..770504a656 100644 --- a/integrations/PostAffiliatePro/utils.js +++ b/integrations/PostAffiliatePro/utils.js @@ -3,6 +3,7 @@ const updateSaleObject = (sale, properties) => { if (properties.total) sale.setTotalCost(properties.total); if (properties.fixedCost) sale.setFixedCost(properties.fixedCost); if (properties.order_id) sale.setOrderID(properties.order_id); + // Post Affiliate Pro supports five extra data only. if (properties.data1) sale.setData1(properties.data1); if (properties.data2) sale.setData2(properties.data2); if (properties.data3) sale.setData3(properties.data3); From 8259b043a0a9f3c83c9c461213df3d37128c199e Mon Sep 17 00:00:00 2001 From: ItsSudip Date: Mon, 6 Dec 2021 08:46:38 +0530 Subject: [PATCH 5/5] Adding comments. --- integrations/PostAffiliatePro/browser.js | 2 +- integrations/index.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/integrations/PostAffiliatePro/browser.js b/integrations/PostAffiliatePro/browser.js index db72cab61b..66061d0f4d 100644 --- a/integrations/PostAffiliatePro/browser.js +++ b/integrations/PostAffiliatePro/browser.js @@ -88,7 +88,7 @@ class PostAffiliatePro { const { message } = rudderElement; const { event } = message; const { properties } = message; - // We are going to call click event, for the events given in dashboard only. + // We are going to call click event, for the event list given in dashboard only. if (clickEventsArr && clickEventsArr.includes(event)) { if (properties) { if (properties.data1) window.Data1 = properties.data1; diff --git a/integrations/index.js b/integrations/index.js index cd9d7e46a9..083f62cdb0 100644 --- a/integrations/index.js +++ b/integrations/index.js @@ -41,8 +41,10 @@ import * as SnapPixel from "./SnapPixel"; import * as TVSquared from "./TVSquared"; import * as VWO from "./VWO"; import * as PostAffiliatePro from "./PostAffiliatePro"; + // the key names should match the destination.name value to keep partity everywhere // (config-plan name, native destination.name , exported integration name(this one below)) + const integrations = { ADOBE_ANALYTICS: AdobeAnalytics.default, AM: Amplitude.default,