@@ -13,6 +13,8 @@ def main():
13
13
createFunnelExperiment ()
14
14
createFeatureExperiment ()
15
15
createAIFeatureExperiment ()
16
+ createSearchEngineIncreaseAddToCartFeatureExperiment ()
17
+ createShortenCollectionsPageIncreaseConversionFunnelExperiment ()
16
18
17
19
def createAIFeatureExperiment ():
18
20
@@ -273,6 +275,131 @@ def createFeatureExperiment():
273
275
print (response .status_code )
274
276
break
275
277
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
+
276
403
def getFunnelFeatureFlagDetails ():
277
404
278
405
ld_api_key = os .getenv ('LD_API_KEY' )
@@ -306,8 +433,7 @@ def getFunnelFeatureFlagDetails():
306
433
time .sleep (5 )
307
434
else :
308
435
print ("Failed to retrieve flag details" )
309
- exit (1 )
310
-
436
+ exit (1 )
311
437
312
438
def createFunnelExperiment ():
313
439
@@ -410,6 +536,132 @@ def createFunnelExperiment():
410
536
print (data )
411
537
print (response .status_code )
412
538
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
413
665
414
666
if __name__ == "__main__" :
415
667
main ()
0 commit comments