Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostAffiliatePro Integration #378

Merged
merged 5 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions integrations/PostAffiliatePro/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* 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";

class PostAffiliatePro {
constructor(config) {
this.name = "POST_AFFILIATE_PRO";
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("pap_x2s6df8d", this.url);
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
}

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;
// 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;
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();
}
// We are supporting only one event for sale.
if (event === "Order Completed") {
const productsArr =
properties && properties.products ? properties.products : null;
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 {
// If any product is not available.
window.sale = window.PostAffTracker.createSale();
}
window.PostAffTracker.register();
}
}

// reset() {
// window.PostAffTracker.setVisitorId(null);
// }
}
export default PostAffiliatePro;
3 changes: 3 additions & 0 deletions integrations/PostAffiliatePro/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import PostAffiliatePro from "./browser";

export default PostAffiliatePro;
23 changes: 23 additions & 0 deletions integrations/PostAffiliatePro/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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);
// 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);
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;
1 change: 1 addition & 0 deletions integrations/client_server_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const clientToServerNames = {
MP: "Mixpanel",
QUALTRICS: "Qualtrics",
SENTRY: "Sentry",
POST_AFFILIATE_PRO: "PostAffiliatePro",
};

export { clientToServerNames };
4 changes: 2 additions & 2 deletions integrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ import * as Sentry from "./Sentry";
import * as SnapPixel from "./SnapPixel";
import * as TVSquared from "./TVSquared";
import * as VWO from "./VWO";

saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down Expand Up @@ -87,6 +86,7 @@ const integrations = {
SNAP_PIXEL: SnapPixel.default,
TVSQUARED: TVSquared.default,
VWO: VWO.default,
POST_AFFILIATE_PRO: PostAffiliatePro.default,
};

export { integrations };
6 changes: 6 additions & 0 deletions integrations/integration_cname.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ const commonNames = {
quantumMetric: "QUANTUMMETRIC",
quantummetric: "QUANTUMMETRIC",
Quantum_Metric: "QUANTUMMETRIC",
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 };