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

ksearch: add cloud choice to analytics reporting #1904

Merged
merged 1 commit into from
Oct 11, 2024
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
3 changes: 2 additions & 1 deletion src/answers-search-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ class AnswersSearchBar {
parsedConfig.businessId,
parsedConfig.analyticsEventsEnabled,
parsedConfig.analyticsOptions,
parsedConfig.environment);
parsedConfig.environment,
parsedConfig.cloudChoice);

this.components.setAnalyticsReporter(this._analyticsReporterService);
}
Expand Down
3 changes: 2 additions & 1 deletion src/answers-umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ class Answers {
parsedConfig.businessId,
parsedConfig.analyticsEventsEnabled,
parsedConfig.analyticsOptions,
parsedConfig.environment);
parsedConfig.environment,
parsedConfig.cloudChoice);

// listen to query id updates
storage.registerListener({
Expand Down
13 changes: 10 additions & 3 deletions src/core/analytics/analyticsreporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default class AnalyticsReporter {
businessId,
analyticsEventsEnabled,
globalOptions = {},
environment = PRODUCTION) {
environment = PRODUCTION,
cloudChoice) {
/**
* The internal business identifier used for reporting
* @type {number}
Expand All @@ -46,12 +47,19 @@ export default class AnalyticsReporter {
*/
this._environment = environment;

/**
* The choice of Cloud Provider
* @type {string}
* @private
*/
this._cloudChoice = cloudChoice;

/**
* Base URL for the analytics API
* @type {string}
* @private
*/
this._baseUrl = getAnalyticsUrl(this._environment);
this._baseUrl = getAnalyticsUrl(this._environment, this._cloudChoice);

/**
* Boolean indicating if opted in or out of conversion tracking
Expand Down Expand Up @@ -134,6 +142,5 @@ export default class AnalyticsReporter {
/** @inheritdoc */
setConversionTrackingEnabled (isEnabled) {
this._conversionTrackingEnabled = isEnabled;
this._baseUrl = getAnalyticsUrl(this._environment, isEnabled);
}
}
27 changes: 13 additions & 14 deletions src/core/utils/urlutils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CloudRegion } from '@yext/search-core';
import { PRODUCTION, SANDBOX, CLOUD_REGION } from '../constants';
import { PRODUCTION, SANDBOX, CLOUD_REGION, GLOBAL_MULTI, GLOBAL_GCP } from '../constants';
import SearchParams from '../../ui/dom/searchparams';
import StorageKeys from '../storage/storagekeys';
import ComponentTypes from '../../ui/components/componenttypes';
Expand All @@ -14,21 +14,20 @@ export function getLiveApiUrl (env = PRODUCTION) {

/**
* Returns the base url for the analytics backend in the desired environment.
* @param {string} env The desired environment.
* @param {boolean} conversionTrackingEnabled If conversion tracking has been opted into.
* @param {string} env The desired environment.]
* @param {string} cloudChoice The choice of cloud provider.
*/
export function getAnalyticsUrl (env = PRODUCTION, conversionTrackingEnabled = false) {
if (isEu()) {
return 'https://www.eu.yextevents.com';
}
if (conversionTrackingEnabled) {
return env === SANDBOX
? 'https://sandbox-realtimeanalytics.yext.com'
: 'https://realtimeanalytics.yext.com';
export function getAnalyticsUrl (env = PRODUCTION, cloudChoice = GLOBAL_MULTI) {
const cloudRegionString = isEu() ? 'eu' : 'us';
let envAndCloudChoice = '';
if (env === SANDBOX && cloudChoice === GLOBAL_GCP) {
envAndCloudChoice = 'sandbox-gcp.';
} else if (env === SANDBOX) {
envAndCloudChoice = 'sandbox.';
} else if (cloudChoice === GLOBAL_GCP) {
envAndCloudChoice = 'gcp.';
}
return env === SANDBOX
? 'https://sandbox-answers.yext-pixel.com'
vijay267 marked this conversation as resolved.
Show resolved Hide resolved
: 'https://answers.yext-pixel.com';
return 'https://' + envAndCloudChoice + cloudRegionString + '.yextevents.com';
}

function isEu () {
Expand Down
10 changes: 5 additions & 5 deletions tests/core/utils/urlutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ describe('getUrlFunctions work', () => {
expect(getAnalyticsUrl(SANDBOX)).toEqual(expect.stringContaining('sandbox'));
});

it('differentiates conversion tracking in analytics url', () => {
expect(getAnalyticsUrl(PRODUCTION, true)).toEqual(expect.stringContaining('realtimeanalytics'));
expect(getAnalyticsUrl(SANDBOX, true)).toEqual(expect.stringContaining('realtimeanalytics'));
it('differentiates gcp from global', () => {
expect(getAnalyticsUrl(PRODUCTION, 'gcp')).toEqual(expect.stringContaining('gcp'));
expect(getAnalyticsUrl(SANDBOX, 'gcp')).toEqual(expect.stringContaining('sandbox-gcp'));

expect(getAnalyticsUrl(PRODUCTION)).not.toEqual(expect.stringContaining('realtimeanalytics'));
expect(getAnalyticsUrl(SANDBOX)).not.toEqual(expect.stringContaining('realtimeanalytics'));
expect(getAnalyticsUrl(PRODUCTION)).not.toEqual(expect.stringContaining('gcp'));
expect(getAnalyticsUrl(SANDBOX)).not.toEqual(expect.stringContaining('sandbox-gcp'));
});
});

Expand Down
Loading