Skip to content

Commit

Permalink
Merge pull request #7638 from artsy/staging
Browse files Browse the repository at this point in the history
Deploy: launch AB test
  • Loading branch information
mzikherman authored May 26, 2021
2 parents 9dd1feb + 99f859d commit c3c95da
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 201 deletions.
10 changes: 9 additions & 1 deletion src/desktop/components/split_test/running_tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@
# this should export empty Object
# module.exports = {}

module.exports = {}
module.exports = {
decayed_merch_v3:
key: "decayed_merch_v3"
outcomes: [
'control'
'experiment'
]
weighting: 'equal'
}
8 changes: 6 additions & 2 deletions src/desktop/components/split_test/splitTestMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NextFunction } from "express"
import { ArtsyRequest, ArtsyResponse } from "lib/middleware/artsyExpress"
import { updateSharifyAndContext } from "lib/middleware/bootstrapSharifyAndContextLocalsMiddleware"
import qs from "qs"
const runningTests = require("./running_tests.coffee")
const SplitTest = require("./server_split_test.coffee")
Expand All @@ -14,7 +15,9 @@ export function splitTestMiddleware(
const name = key.toUpperCase()
if (!res.locals.sd[name]) {
const test = new SplitTest(req, res, configuration)
res.locals.sd[name] = test.outcome()
const outcome = test.outcome()

updateSharifyAndContext(res, name, outcome)
}
}

Expand All @@ -26,7 +29,8 @@ export function splitTestMiddleware(
const test = new SplitTest(req, res, runningTests[key])
const value = params[key]
test.set(value)
res.locals.sd[key.toUpperCase()] = value

updateSharifyAndContext(res, key.toUpperCase(), value)
}
}

Expand Down
1 change: 0 additions & 1 deletion src/desktop/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ module.exports =
MOBILE_MEDIA_QUERY: "only screen and (max-width: 640px)"
NODE_ENV: 'development'
OPENREDIS_URL: null
PAGE_CACHE_ENABLED: false
PAGE_CACHE_TYPES: 'artist'
PAGE_CACHE_NAMESPACE: 'page-cache'
PAGE_CACHE_VERSION: '1'
Expand Down
64 changes: 0 additions & 64 deletions src/lib/middleware/__tests__/pageCache.jest.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function bootstrapSharifyAndContextLocalsMiddleware(
* Updates both the sharify locals for template injection along with the context
* globals for the request.
*/
function updateSharifyAndContext(res, key, value) {
export function updateSharifyAndContext(res, key, value) {
res.locals.sd[key] = value
const asyncLocalStorage = getAsyncLocalStorage()
asyncLocalStorage.getStore()?.set(key, value)
Expand Down
115 changes: 0 additions & 115 deletions src/lib/middleware/pageCache.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { escapedFragmentMiddleware } from "./lib/middleware/escapedFragment"
import { hardcodedRedirectsMiddleware } from "./lib/middleware/hardcodedRedirects"
import { localsMiddleware } from "./lib/middleware/locals"
import { marketingModalsMiddleware } from "./lib/middleware/marketingModals"
import { pageCacheMiddleware } from "./lib/middleware/pageCache"
import { proxyReflectionMiddleware } from "./lib/middleware/proxyReflection"
import { sameOriginMiddleware } from "./lib/middleware/sameOrigin"
import { unsupportedBrowserMiddleware } from "./lib/middleware/unsupportedBrowser"
Expand Down Expand Up @@ -110,7 +109,6 @@ export function initializeMiddleware(app) {
app.use(sameOriginMiddleware)
app.use(escapedFragmentMiddleware)
app.use(unsupportedBrowserMiddleware)
app.use(pageCacheMiddleware)

/**
* Blank page used by Eigen for caching web views.
Expand Down
1 change: 1 addition & 0 deletions src/typings/sharify.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ declare module "sharify" {
readonly CMS_URL: string
CURRENT_PATH: string
CURRENT_USER: User
readonly DECAYED_MERCH_V3: string // TODO: Remove after A/B test
readonly DEPLOY_ENV: string
readonly EIGEN: boolean
readonly ENABLE_NEW_ARTWORK_FILTERS: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Match, RouterState, withRouter } from "found"
import React from "react"
import { RelayRefetchProp, createRefetchContainer, graphql } from "react-relay"
import { ZeroState } from "./ZeroState"
import { getENV } from "v2/Utils/getENV"

interface ArtistArtworkFilterProps {
artist: ArtistArtworkFilter_artist
Expand All @@ -24,18 +25,31 @@ const ArtistArtworkFilter: React.FC<ArtistArtworkFilterProps> = props => {
// we still want to render the rest of the page.
if (!hasFilter) return null

const sortOptions = [
{ value: "-has_price,-prices", text: "Price (desc.)" },
{ value: "-has_price,prices", text: "Price (asc.)" },
{ value: "-partner_updated_at", text: "Recently updated" },
{ value: "-published_at", text: "Recently added" },
{ value: "-year", text: "Artwork year (desc.)" },
{ value: "year", text: "Artwork year (asc.)" },
]

const defaultSortValue =
getENV("DECAYED_MERCH_V3") === "experiment"
? "-decayed_merch_v2"
: "-decayed_merch"

sortOptions.unshift({ value: defaultSortValue, text: "Default" })

const initialFilters = {
...(match && match.location.query),
sort: defaultSortValue,
}

return (
<ArtworkFilterContextProvider
filters={match && match.location.query}
sortOptions={[
{ value: "-decayed_merch", text: "Default" },
{ value: "-has_price,-prices", text: "Price (desc.)" },
{ value: "-has_price,prices", text: "Price (asc.)" },
{ value: "-partner_updated_at", text: "Recently updated" },
{ value: "-published_at", text: "Recently added" },
{ value: "-year", text: "Artwork year (desc.)" },
{ value: "year", text: "Artwork year (asc.)" },
]}
filters={initialFilters}
sortOptions={sortOptions}
// @ts-expect-error STRICT_NULL_CHECK
aggregations={sidebarAggregations.aggregations as any}
// @ts-expect-error STRICT_NULL_CHECK
Expand Down
6 changes: 6 additions & 0 deletions src/v2/Apps/Artist/artistRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,15 @@ export const artistRoutes: AppRouteConfig[] = [
// renders (such as tabbing back to this route in your browser) will not.
const filterStateFromUrl = props.location ? props.location.query : {}

const sort =
getENV("DECAYED_MERCH_V3") === "experiment"
? "-decayed_merch_v2"
: "-decayed_merch"

const filterParams = {
...initialArtworkFilterState,
...paramsToCamelCase(filterStateFromUrl),
sort,
}

// filterParams.hasFilter = Object.entries(filterParams).some(
Expand Down
29 changes: 28 additions & 1 deletion src/v2/Artsy/Analytics/__tests__/trackingMiddleware.jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare const global: any
jest.mock("sharify", () => ({
data: {
APP_URL: "http://testing.com",
ALL_ARTWORKS_AS_CATS: "experiment",
},
}))

Expand All @@ -19,7 +20,7 @@ describe("trackingMiddleware", () => {
beforeEach(() => {
// FIXME: reaction migration
// @ts-ignore
window.analytics = { page: jest.fn() }
window.analytics = { track: jest.fn(), page: jest.fn() }
})

afterEach(() => {
Expand Down Expand Up @@ -145,4 +146,30 @@ describe("trackingMiddleware", () => {
})
})
})

describe("triggering AB test experiment viewed events", () => {
it("triggers for a given route", () => {
trackingMiddleware({
abTestRouteMap: [
{ abTest: "all_artworks_as_cats", routes: ["/artwork(.*)"] },
],
})(store)(noop)({
type: ActionTypes.UPDATE_LOCATION,
payload: {
pathname: "/artwork/some-id",
},
})
expect(global.analytics.track).toBeCalledWith(
"Experiment Viewed",
{
experiment_id: "all_artworks_as_cats",
experiment_name: "all_artworks_as_cats",
variation_id: "experiment",
variation_name: "experiment",
nonInteraction: 1,
},
{ page: {} }
)
})
})
})
2 changes: 1 addition & 1 deletion src/v2/Artsy/Analytics/trackExperimentViewed.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Schema from "v2/Artsy/Analytics"
import { data as sd } from "sharify"

export const trackExperimentViewed = (name: string, trackingData) => {
export const trackExperimentViewed = (name: string, trackingData = {}) => {
if (typeof window.analytics !== "undefined") {
const variation = sd[name.toUpperCase()]
if (!Boolean(variation)) {
Expand Down
Loading

0 comments on commit c3c95da

Please sign in to comment.