| 
 | 1 | +<script setup lang="ts">  | 
 | 2 | +import { inject, ref } from 'vue'  | 
 | 3 | +import { type Client, type OptimizelyUserContext } from '@optimizely/optimizely-sdk'  | 
 | 4 | +import DecisionOutput from '../components/DecisionOutput.vue'  | 
 | 5 | +import Warning from '../components/WarningComponent.vue'  | 
 | 6 | +import { type Result } from '../types/Result'  | 
 | 7 | +
  | 
 | 8 | +const optimizelyClient = inject('optimizeClient') as Client  | 
 | 9 | +
  | 
 | 10 | +let projectId: string = ''  | 
 | 11 | +const datafile = optimizelyClient.getOptimizelyConfig()?.getDatafile();  | 
 | 12 | +if (datafile) {  | 
 | 13 | +  projectId = JSON.parse(datafile).projectId  | 
 | 14 | +}  | 
 | 15 | +
  | 
 | 16 | +const results: Result[] = []  | 
 | 17 | +for (let i = 0; i < 10; i++) {  | 
 | 18 | +  const userId = (Math.floor(Math.random() * (10000 - 1000) + 1000)).toString();  | 
 | 19 | +
  | 
 | 20 | +  const user = optimizelyClient.createUserContext(userId)  | 
 | 21 | +
  | 
 | 22 | +  const decision = user?.decide('product_sort')  | 
 | 23 | +  if (!decision) {  | 
 | 24 | +    continue  | 
 | 25 | +  }  | 
 | 26 | +
  | 
 | 27 | +  results.push({  | 
 | 28 | +    userId,  | 
 | 29 | +    variation: decision.variationKey,  | 
 | 30 | +    sortMethod: decision.variables['sort_method'],  | 
 | 31 | +  })  | 
 | 32 | +}  | 
 | 33 | +</script>  | 
 | 34 | + | 
1 | 35 | <template>  | 
2 |  | -  <div class="run">  | 
 | 36 | +  <section class="run">  | 
3 | 37 |     <h1>Experiment Output</h1>  | 
4 |  | -    <p>[Loop through the results]</p>  | 
5 |  | -  </div>  | 
 | 38 | +    <output v-if="results.length">  | 
 | 39 | +      <DecisionOutput v-for="result in results" :key="result.userId" :result="result" />  | 
 | 40 | +    </output>  | 
 | 41 | +    <Warning v-else>  | 
 | 42 | +      <p>  | 
 | 43 | +        No results found.  | 
 | 44 | +      </p>  | 
 | 45 | +      <p>Some reasons could include:</p>  | 
 | 46 | +      <ol>  | 
 | 47 | +        <li>Flag was off for everyone.</li>  | 
 | 48 | +        <li>Your sample size of visitors was too small. Rerun, or increase the iterations in the FOR loop.</li>  | 
 | 49 | +        <li>By default you have 2 keys for 2 project environments (dev/prod). Verify in Settings > Environments that you  | 
 | 50 | +          used the right key for the environment where your flag is toggled to ON.</li>  | 
 | 51 | +      </ol>  | 
 | 52 | +      <p>  | 
 | 53 | +        Check your key and project configuration on  | 
 | 54 | +        <a v-if="projectId !== ''"  | 
 | 55 | +          :href="'https://app.optimizely.com/v2/projects/' + projectId + '/settings/implementation'">settings page</a>  | 
 | 56 | +        <a v-else href="https://app.optimizely.com/v2/projects/">settings page</a>  | 
 | 57 | +      </p>  | 
 | 58 | +    </Warning>  | 
 | 59 | +  </section>  | 
6 | 60 | </template>  | 
7 | 61 | 
 
  | 
8 |  | -<style>  | 
 | 62 | +<style scoped>  | 
9 | 63 | @media (min-width: 1024px) {  | 
10 | 64 |   .run {  | 
11 | 65 |     min-height: 100vh;  | 
 | 
0 commit comments