Skip to content

Commit

Permalink
Version 1.17.7
Browse files Browse the repository at this point in the history
**Changes**

- Adjusts analytics urls to leverage new endpoints and respect cloudChoice #1904
  • Loading branch information
Fondryext authored Oct 15, 2024
2 parents 65ba461 + 97e65c7 commit dfda7bc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/answers-search-ui",
"version": "1.17.6",
"version": "1.17.7",
"description": "Javascript Search Programming Interface",
"main": "dist/answers-umd.js",
"repository": {
Expand Down
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
15 changes: 11 additions & 4 deletions src/core/analytics/analyticsreporter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @module AnalyticsReporter */

import AnalyticsEvent from './analyticsevent';
import { PRODUCTION } from '../constants';
import { GLOBAL_MULTI, PRODUCTION } from '../constants';
import HttpRequester from '../http/httprequester';
import { getAnalyticsUrl } from '../utils/urlutils';

Expand All @@ -19,7 +19,8 @@ export default class AnalyticsReporter {
businessId,
analyticsEventsEnabled,
globalOptions = {},
environment = PRODUCTION) {
environment = PRODUCTION,
cloudChoice = GLOBAL_MULTI) {
/**
* 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'
: '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

0 comments on commit dfda7bc

Please sign in to comment.