Skip to content

Commit 80e38cf

Browse files
Ahmed QadriAhmed Qadri
Ahmed Qadri
authored and
Ahmed Qadri
committed
CKO Build (draft)
2 parents 643a916 + 251081a commit 80e38cf

37 files changed

+2057
-852
lines changed

Diff for: .github/workflows/old_resources/ld_api/create_experiment.py

+254-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def main():
1313
createFunnelExperiment()
1414
createFeatureExperiment()
1515
createAIFeatureExperiment()
16+
createSearchEngineIncreaseAddToCartFeatureExperiment()
17+
createShortenCollectionsPageIncreaseConversionFunnelExperiment()
1618

1719
def createAIFeatureExperiment():
1820

@@ -273,6 +275,131 @@ def createFeatureExperiment():
273275
print(response.status_code)
274276
break
275277

278+
def getearchEngineIncreaseAddToCartFeatureFlagDetails():
279+
280+
ld_api_key = os.getenv('LD_API_KEY')
281+
namespace = os.getenv('NAMESPACE')
282+
project_key = f"{namespace}-ld-demo"
283+
flag_key = "release-new-search-engine"
284+
285+
if not ld_api_key:
286+
print("LD_API_KEY not set")
287+
exit(1)
288+
289+
if not namespace:
290+
print("NAMESPACE not set")
291+
exit(1)
292+
293+
url = "https://app.launchdarkly.com/api/v2/flags/" + project_key + "/" + flag_key
294+
295+
headers = {
296+
"Content-Type": "application/json",
297+
"Authorization": ld_api_key,
298+
}
299+
while True:
300+
response = requests.get(url, headers=headers)
301+
302+
if response.status_code == 200:
303+
print("Flag details retrieved successfully")
304+
return response.json().get("variations")
305+
elif response.status_code == 429:
306+
print("Rate limit exceeded, waiting 10 seconds to retry...")
307+
time.sleep(5)
308+
else:
309+
print("Failed to retrieve flag details")
310+
exit(1)
311+
312+
def createSearchEngineIncreaseAddToCartFeatureExperiment():
313+
314+
ld_api_key = os.getenv('LD_API_KEY')
315+
namespace = os.getenv('NAMESPACE')
316+
project_key = f"{namespace}-ld-demo"
317+
318+
if not ld_api_key:
319+
print("LD_API_KEY not set")
320+
exit(1)
321+
322+
if not namespace:
323+
print("NAMESPACE not set")
324+
exit(1)
325+
326+
variations = getearchEngineIncreaseAddToCartFeatureFlagDetails()
327+
328+
url = "https://app.launchdarkly.com/api/v2/projects/" + project_key + "/environments/" + namespace + "/experiments"
329+
330+
payload = {
331+
"name": "Search Engine Increase Add To Cart",
332+
"description": "See if new precise search engine with direct add to cart button lead to increase in cart prices",
333+
"maintainerId": "6127d90d9971632664df6f1a",
334+
"key": "search-engine-add-to-cart-experiment",
335+
"iteration": {
336+
"hypothesis": "If we enable the new search engine feature, we can drive greater upsell conversion.",
337+
"canReshuffleTraffic": True,
338+
"metrics": [
339+
{
340+
"key": "search-engine-add-to-cart",
341+
"isGroup": False,
342+
},
343+
{
344+
"key": "in-cart-total-price",
345+
"isGroup": False,
346+
}
347+
],
348+
"primarySingleMetricKey": "search-engine-add-to-cart",
349+
"treatments": [
350+
{
351+
"name": variations[0]['name'],
352+
"baseline": True,
353+
"allocationPercent": "50",
354+
"parameters": [
355+
{
356+
"flagKey": "release-new-search-engine",
357+
"variationId": variations[0]['_id']
358+
}
359+
]
360+
},
361+
{
362+
"name": variations[1]['name'],
363+
"allocationPercent": "50",
364+
"parameters": [
365+
{
366+
"flagKey": "release-new-search-engine",
367+
"variationId": variations[1]['_id']
368+
}
369+
]
370+
},
371+
],
372+
"flags": {
373+
"release-new-search-engine": {
374+
"ruleId": "fallthrough",
375+
"flagConfigVersion": 1
376+
},
377+
},
378+
"randomizationUnit": "audience"
379+
}
380+
}
381+
382+
headers = {
383+
"Content-Type": "application/json",
384+
"Authorization": ld_api_key,
385+
"LD-API-Version": "beta"
386+
}
387+
388+
response = requests.post(url, json=payload, headers=headers)
389+
390+
while True:
391+
if response.status_code == 201:
392+
print("Search Engine Increase Add To Cart Feature Experiment created successfully")
393+
break
394+
elif response.status_code == 429:
395+
print("Rate limit exceeded, waiting 10 seconds to retry...")
396+
time.sleep(10)
397+
else:
398+
data = response.json()
399+
print(data)
400+
print(response.status_code)
401+
break
402+
276403
def getFunnelFeatureFlagDetails():
277404

278405
ld_api_key = os.getenv('LD_API_KEY')
@@ -306,8 +433,7 @@ def getFunnelFeatureFlagDetails():
306433
time.sleep(5)
307434
else:
308435
print("Failed to retrieve flag details")
309-
exit(1)
310-
436+
exit(1)
311437

312438
def createFunnelExperiment():
313439

@@ -410,6 +536,132 @@ def createFunnelExperiment():
410536
print(data)
411537
print(response.status_code)
412538
break
539+
540+
def getShortenCollectionsPageIncreaseConversionFunnelFeatureFlagDetails():
541+
542+
ld_api_key = os.getenv('LD_API_KEY')
543+
namespace = os.getenv('NAMESPACE')
544+
project_key = f"{namespace}-ld-demo"
545+
flag_key = "release-new-shorten-collections-page"
546+
547+
if not ld_api_key:
548+
print("LD_API_KEY not set")
549+
exit(1)
550+
551+
if not namespace:
552+
print("NAMESPACE not set")
553+
exit(1)
554+
555+
url = "https://app.launchdarkly.com/api/v2/flags/" + project_key + "/" + flag_key
556+
557+
headers = {
558+
"Content-Type": "application/json",
559+
"Authorization": ld_api_key,
560+
}
561+
while True:
562+
response = requests.get(url, headers=headers)
563+
564+
565+
if response.status_code == 200:
566+
print("Flag details retrieved successfully")
567+
return response.json().get("variations")
568+
elif response.status_code == 429:
569+
print("Rate limit exceeded, waiting 10 seconds to retry...")
570+
time.sleep(5)
571+
else:
572+
print("Failed to retrieve flag details")
573+
exit(1)
574+
575+
def createShortenCollectionsPageIncreaseConversionFunnelExperiment():
576+
577+
ld_api_key = os.getenv('LD_API_KEY')
578+
namespace = os.getenv('NAMESPACE')
579+
project_key = f"{namespace}-ld-demo"
580+
581+
if not ld_api_key:
582+
print("LD_API_KEY not set")
583+
exit(1)
584+
585+
if not namespace:
586+
print("NAMESPACE not set")
587+
exit(1)
588+
589+
variations = getShortenCollectionsPageIncreaseConversionFunnelFeatureFlagDetails()
590+
591+
url = "https://app.launchdarkly.com/api/v2/projects/" + project_key + "/environments/" + namespace + "/experiments"
592+
593+
payload = {
594+
"name": "Shorten Collections Page Increase Conversion",
595+
"description": "Does shortening the collections page to the top 3 items increase conversion versus showing all of the collection?",
596+
"maintainerId": "6127d90d9971632664df6f1a",
597+
"key": "shorten-collections-page-increase-conversion-funnel-experiment",
598+
"iteration": {
599+
"hypothesis": "Does shortening the collections page to the top 3 items increase conversion versus showing all of the collection?",
600+
"canReshuffleTraffic": True,
601+
"metrics": [
602+
{
603+
"key": "shorten-collections-page-store-checkout-metrics",
604+
"isGroup": True,
605+
},
606+
{
607+
"key": "in-cart-total-price",
608+
"isGroup": False,
609+
}
610+
],
611+
"primaryFunnelKey": "shorten-collections-page-store-checkout-metrics",
612+
"treatments": [
613+
{
614+
"name": variations[0]['name'],
615+
"baseline": True,
616+
"allocationPercent": "50",
617+
"parameters": [
618+
{
619+
"flagKey": "release-new-shorten-collections-page",
620+
"variationId": variations[0]['_id']
621+
}
622+
]
623+
},
624+
{
625+
"name": variations[1]['name'],
626+
"allocationPercent": "50",
627+
"parameters": [
628+
{
629+
"flagKey": "release-new-shorten-collections-page",
630+
"variationId": variations[1]['_id']
631+
}
632+
]
633+
},
634+
],
635+
"flags": {
636+
"release-new-shorten-collections-page": {
637+
"ruleId": "fallthrough",
638+
"flagConfigVersion": 1
639+
},
640+
},
641+
"randomizationUnit": "audience"
642+
}
643+
}
644+
645+
headers = {
646+
"Content-Type": "application/json",
647+
"Authorization": ld_api_key,
648+
"LD-API-Version": "beta"
649+
}
650+
651+
response = requests.post(url, json=payload, headers=headers)
652+
653+
while True:
654+
if response.status_code == 201:
655+
print("Shorten Collections Page Increase Conversion Funnel Experiment created successfully")
656+
break
657+
elif response.status_code == 429:
658+
print("Rate limit exceeded, waiting 10 seconds to retry...")
659+
time.sleep(10)
660+
else:
661+
data = response.json()
662+
print(data)
663+
print(response.status_code)
664+
break
413665

414666
if __name__ == "__main__":
415667
main()

Diff for: .github/workflows/old_resources/ld_api/create_ld_featureflags.py

+77-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def main():
2626
createCartSuggestedItemsFeatureFlag()
2727
createDestinationRecommendationFeatureFlag()
2828
createAIChatbotModelsFeatureFlag()
29+
createReleaseNewSearchEngineFeatureFlag()
30+
createReleaseNewShortenCollectionsPageFeatureFlag()
2931

3032
def createAIChatbotModelsFeatureFlag():
3133

@@ -369,7 +371,81 @@ def createStoreAttentionCalloutFeatureFlag():
369371
response = requests.request("POST", BASE_URL + url, headers = {'Authorization': ld_api_key, 'Content-Type': 'application/json'}, data = json.dumps(payload))
370372
if(response.status_code == 201):
371373
print("Store attention callout feature flag created successfully.")
372-
374+
375+
def createReleaseNewShortenCollectionsPageFeatureFlag():
376+
377+
print("Creating Release New Shorten Collections Page feature flag...")
378+
379+
url = "/flags/" + project_key
380+
381+
payload = {
382+
"clientSideAvailability": {
383+
"usingEnvironmentId": True,
384+
"usingMobileKey": True
385+
},
386+
"key": "release-new-shorten-collections-page",
387+
"name": "Release New Shorten Collections Page",
388+
"description": "In Marketplace, after you click on a collection, you would now see a New Shorten Collections Page.",
389+
"variations": [
390+
{
391+
"value": "old-long-collections-page",
392+
"name": "Old Long Collections Page"
393+
},
394+
{
395+
"value": "new-shorten-collections-page",
396+
"name": "New Shorten Collections Page"
397+
}
398+
],
399+
"defaults":{
400+
"onVariation": 0,
401+
"offVariation": 0
402+
},
403+
"tags": [
404+
"experiment"
405+
]
406+
}
407+
408+
response = requests.request("POST", BASE_URL + url, headers = {'Authorization': ld_api_key, 'Content-Type': 'application/json'}, data = json.dumps(payload))
409+
if(response.status_code == 201):
410+
print("Release New Shorten Collections Page feature flag created successfully.")
411+
412+
def createReleaseNewSearchEngineFeatureFlag():
413+
414+
print("Creating Release New Search Engine feature flag...")
415+
416+
url = "/flags/" + project_key
417+
418+
payload = {
419+
"clientSideAvailability": {
420+
"usingEnvironmentId": True,
421+
"usingMobileKey": True
422+
},
423+
"key": "release-new-search-engine",
424+
"name": "Release New Search Engine",
425+
"description": "In Marketplace, you get a new search engine that has an add to cart button.",
426+
"variations": [
427+
{
428+
"value": "old-search-engine",
429+
"name": "Old Search Engine"
430+
},
431+
{
432+
"value": "new-search-engine",
433+
"name": "New Search Engine"
434+
}
435+
],
436+
"defaults":{
437+
"onVariation": 0,
438+
"offVariation": 0
439+
},
440+
"tags": [
441+
"experiment"
442+
]
443+
}
444+
445+
response = requests.request("POST", BASE_URL + url, headers = {'Authorization': ld_api_key, 'Content-Type': 'application/json'}, data = json.dumps(payload))
446+
if(response.status_code == 201):
447+
print("Release New Search Engine feature flag created successfully.")
448+
373449
def createCartSuggestedItemsFeatureFlag():
374450

375451
print("Creating cartSuggestedItems feature flag...")

0 commit comments

Comments
 (0)