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: Changes for websites that do not redirect non www url to www url #248

Merged
merged 2 commits into from
May 8, 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
24 changes: 21 additions & 3 deletions src/experimentation/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import URI from 'urijs';
import { hasText } from '@adobe/spacecat-shared-utils';
import RUMAPIClient, { createExperimentationURL } from '@adobe/spacecat-shared-rum-api-client';
import { AuditBuilder } from '../common/audit-builder.js';
import { getRUMUrl } from '../support/utils.js';
Expand All @@ -29,14 +31,30 @@ function processRUMResponse(data) {
}));
}

export function hasNonWWWSubdomain(baseUrl) {
try {
const uri = new URI(baseUrl);
return hasText(uri.domain()) && hasText(uri.subdomain()) && uri.subdomain() !== 'www';
} catch (e) {
throw new Error(`Cannot parse baseURL: ${baseUrl}`);
}
}

async function processAudit(baseURL, context) {
const rumAPIClient = RUMAPIClient.createFrom(context);
const finalUrl = await getRUMUrl(baseURL);
const params = {
let finalUrl = await getRUMUrl(baseURL);
let params = {
url: finalUrl,
};

const data = await rumAPIClient.getExperimentationData(params);
let data = await rumAPIClient.getExperimentationData(params);
if (data.length === 0 && !hasNonWWWSubdomain(baseURL) && !finalUrl.toLowerCase().startsWith('www')) {
finalUrl = `www.${finalUrl}`;
params = {
url: finalUrl,
};
data = await rumAPIClient.getExperimentationData(params);
}
return {
auditResult: processRUMResponse(data),
fullAuditRef: createExperimentationURL({ url: finalUrl }),
Expand Down
56 changes: 53 additions & 3 deletions test/audits/experimentation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ import chai from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import nock from 'nock';
import { experimentationAuditRunner } from '../../src/experimentation/handler.js';
import { expectedAuditData, rumData } from '../fixtures/experimentation-data.js';
import { experimentationAuditRunner, hasNonWWWSubdomain } from '../../src/experimentation/handler.js';
import {
expectedAuditDataVariant1,
expectedAuditDataVariant2,
expectedAuditDataVariant3,
rumData,
rumDataEmpty,
} from '../fixtures/experimentation-data.js';

chai.use(sinonChai);
const { expect } = chai;
Expand Down Expand Up @@ -62,6 +68,50 @@ describe('Experimentation Audit', () => {
})
.reply(200, rumData);
const auditData = await experimentationAuditRunner('https://bamboohr.com', context);
expect(auditData).to.deep.equal(expectedAuditData);
expect(auditData).to.deep.equal(expectedAuditDataVariant1);
});

it('fetch experiment data for base url > process > sends zero results', async () => {
nock('https://spacecat.com')
.get('/')
.reply(200);
nock('https://helix-pages.anywhere.run')
.get('/helix-services/run-query@v3/rum-experiments')
.query({
...DOMAIN_REQUEST_DEFAULT_PARAMS,
domainkey: context.env.RUM_DOMAIN_KEY,
url: 'spacecat.com',
})
.reply(200, rumDataEmpty);
nock('https://helix-pages.anywhere.run')
.get('/helix-services/run-query@v3/rum-experiments')
.query({
...DOMAIN_REQUEST_DEFAULT_PARAMS,
domainkey: context.env.RUM_DOMAIN_KEY,
url: 'www.spacecat.com',
})
.reply(200, rumData);
const auditData = await experimentationAuditRunner('https://spacecat.com', context);
expect(auditData).to.deep.equal(expectedAuditDataVariant2);
});

it('fetch experiment data for base url > process > sends zero results', async () => {
nock('https://subdomain.spacecat.com')
.get('/')
.reply(200);
nock('https://helix-pages.anywhere.run')
.get('/helix-services/run-query@v3/rum-experiments')
.query({
...DOMAIN_REQUEST_DEFAULT_PARAMS,
domainkey: context.env.RUM_DOMAIN_KEY,
url: 'subdomain.spacecat.com',
})
.reply(200, rumDataEmpty);
const auditData = await experimentationAuditRunner('https://subdomain.spacecat.com', context);
expect(auditData).to.deep.equal(expectedAuditDataVariant3);
});

it('throws error when parse fails', () => {
expect(() => hasNonWWWSubdomain('https://spacecat,com')).to.throw('Cannot parse baseURL: https://spacecat,com');
});
});
178 changes: 177 additions & 1 deletion test/fixtures/experimentation-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
export const expectedAuditData = {
export const expectedAuditDataVariant1 = {
fullAuditRef: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-experiments?interval=7&offset=0&limit=101&url=bamboohr.com',
auditResult: [
{
Expand Down Expand Up @@ -87,6 +87,89 @@ export const expectedAuditData = {
],
};

export const expectedAuditDataVariant2 = {
fullAuditRef: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-experiments?interval=7&offset=0&limit=101&url=www.spacecat.com',
auditResult: [
{
experiment: '24-101c-lp-enhanced-applicant-tracking-system',
p_value: 0.5000000005,
variant: 'challenger-2',
variant_experimentation_events: 13,
variant_conversion_events: 3,
variant_experimentations: '1300',
variant_conversions: '300',
variant_conversion_rate: '0.230769231',
time5: '2024-02-01 17:00:19+00',
time95: '2024-02-07 20:00:55+00',
},
{
experiment: '24-101c-lp-enhanced-applicant-tracking-system',
p_value: 0.5000000005,
variant: 'challenger-1',
variant_experimentation_events: 11,
variant_conversion_events: 3,
variant_experimentations: '1100',
variant_conversions: '300',
variant_conversion_rate: '0.272727273',
time5: '2024-02-01 00:00:08+00',
time95: '2024-02-07 23:00:58+00',
},
{
experiment: '24-101a-lp-enhanced-onboarding',
p_value: 0.5000000005,
variant: 'challenger-1',
variant_experimentation_events: 23,
variant_conversion_events: 8,
variant_experimentations: '2300',
variant_conversions: '800',
variant_conversion_rate: '0.347826087',
time5: '2024-02-01 13:00:04+00',
time95: '2024-02-07 21:00:08+00',
},
{
experiment: '24-101a-lp-enhanced-onboarding',
p_value: 0.5000000005,
variant: 'challenger-2',
variant_experimentation_events: 31,
variant_conversion_events: 3,
variant_experimentations: '3100',
variant_conversions: '300',
variant_conversion_rate: '0.096774194',
time5: '2024-02-01 15:00:13+00',
time95: '2024-02-07 20:00:18+00',
},
{
experiment: '2-21-free-trial-cp-delay-load',
p_value: 0.3431751933689274,
variant: 'challenger-1',
variant_experimentation_events: 24,
variant_conversion_events: 20,
variant_experimentations: '2400',
variant_conversions: '2000',
variant_conversion_rate: '0.833333333',
time5: '2024-02-01 00:00:08+00',
time95: '2024-02-07 23:00:12+00',
},
{
experiment: '2-21-free-trial-cp-delay-load',
p_value: 0.47701597063430096,
variant: 'challenger-2',
variant_experimentation_events: 24,
variant_conversion_events: 13,
variant_experimentations: '2400',
variant_conversions: '1300',
variant_conversion_rate: '0.541666667',
time5: '2024-02-01 18:00:00+00',
time95: '2024-02-07 19:00:09+00',
},
],
};

export const expectedAuditDataVariant3 = {
fullAuditRef: 'https://helix-pages.anywhere.run/helix-services/run-query@v3/rum-experiments?interval=7&offset=0&limit=101&url=subdomain.spacecat.com',
auditResult: [],
};

export const rumData = {
':names': [
'results',
Expand Down Expand Up @@ -340,3 +423,96 @@ export const rumData = {
],
},
};

export const rumDataEmpty = {
':names': [
'results',
'meta',
],
':type': 'multi-sheet',
':version': 3,
results: {
limit: 1,
offset: 0,
total: 0,
data: [],
columns: [],
},
meta: {
limit: 13,
offset: 0,
total: 13,
columns: [
'name',
'value',
'type',
],
data: [
{
name: 'description',
value: 'Using Helix RUM data, get a report of conversion rates of experiment variants compared to control, including p value.',
type: 'query description',
},
{
name: 'url',
value: 'maidenform.com',
type: 'request parameter',
},
{
name: 'interval',
value: 7,
type: 'request parameter',
},
{
name: 'offset',
value: 0,
type: 'request parameter',
},
{
name: 'startdate',
value: '-',
type: 'request parameter',
},
{
name: 'enddate',
value: '-',
type: 'request parameter',
},
{
name: 'timezone',
value: 'UTC',
type: 'request parameter',
},
{
name: 'experiment',
value: '-',
type: 'request parameter',
},
{
name: 'conversioncheckpoint',
value: 'click',
type: 'request parameter',
},
{
name: 'sources',
value: '-',
type: 'request parameter',
},
{
name: 'targets',
value: '-',
type: 'request parameter',
},
{
name: 'threshold',
value: '500',
type: 'request parameter',
},
{
name: 'limit',
value: null,
type: 'request parameter',
},
],
},
};
Loading