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

Fix visitor consumer #516

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 17 additions & 12 deletions _src/scripts/libs/data-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,14 @@ export class Visitor {
}

if (window.Visitor) {
Visitor.#instance = window.Visitor.getInstance(this.#instanceID);
this.#instance = window.Visitor.getInstance(this.#instanceID);
resolve();
return;
}

document.addEventListener('at-library-loaded', () => {
if (window.Visitor) {
Visitor.#instance = window.Visitor.getInstance(this.#instanceID);
this.#instance = window.Visitor.getInstance(this.#instanceID);
}
resolve();
})
Expand All @@ -589,15 +589,6 @@ export class Visitor {
return !this.#instance || url.includes("adobe_mc") ? url : this.#instance.appendVisitorIDsTo(url);
}

/**
*
* @returns {Promise<string>}
*/
static async getConsumerId() {
await this.#staticInit;
return this.#instance?._supplementalDataIDCurrent ? this.#instance._supplementalDataIDCurrent : "";
}

/**
*
* @returns {Promise<string>}
Expand Down Expand Up @@ -674,6 +665,12 @@ export class Target {
*/
static #buyLinksMbox = this.getOffer('buyLinks-mbox');

/**
* @typedef {{content: {geoIpPrice: string}}} GeoIpPriceMbox
* @type {Promise<GeoIpPriceMbox|null>}
*/
static #geoIpFlagMbox = this.getOffer('geoip-flag-mbox');

/**
* get the product-buy link mappings from Target (
* e.g
Expand Down Expand Up @@ -701,6 +698,14 @@ export class Target {
return (await this.#campaignMbox)?.content?.pid || null;
}

/**
*
* @returns {Promise<string|null>}
*/
static async getGeoIpFlagMbox() {
return (await this.#geoIpFlagMbox)?.content?.geoIpPrice || null;
}

/**
* Awaits Target to apply load and apply its changes
* @returns {Promise<void>}
Expand Down Expand Up @@ -739,7 +744,7 @@ export class Target {

try {
offers = await window.adobe?.target?.getOffers({
consumerId: await Visitor.getConsumerId(),
consumerId: window.crypto.randomUUID(),
request: {
id: {
marketingCloudVisitorId: await Visitor.getMarketingCloudVisitorId()
Expand Down
12 changes: 1 addition & 11 deletions _src/scripts/libs/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,19 +700,9 @@ class Vlaicu {
static #isSohoCornerCase = (productId) =>
Constants.SOHO_CORNER_CASES_LOCALSE.includes(Page.locale) && productId === "com.bitdefender.soho"

static #getGeoIpFlag = async () => {
const offer = await Target.getOffer('geoip-flag-mbox');

if (offer && offer.content && typeof offer.content.geoIpPrice !== 'undefined') {
return offer.content.geoIpPrice;
}

return null;
}

static async getProductVariations(productId, campaign) {
let locale = this.#isSohoCornerCase(productId) ? "en-mt" : Page.locale;
let geoIpFlag = await this.#getGeoIpFlag();
let geoIpFlag = await Target.getGeoIpFlagMbox();
if (geoIpFlag) {
locale = await User.locale;
}
Expand Down