Sun Dec 08 2019
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
<template>
  <form @submit.prevent='handleSubmit'>
    <div class="language-select" @click='onLanguageDropdownClick'>
      <div class="selected-language">
        <span 
          class='flag'
          :style="`background-image:url(/nuxt-assets/img/icons/flags/${$store.state.langcode}.svg`">
        </span>
        <span>{{ $store.getters['selectedLanguage'].name }}</span>
      </div>
      <ul v-if="isDropdownVisible">
        <li 
          v-for='language in $store.state.languages' 
          :data-code='language.code'
          :key='language.code'
          @click='onLanguageChange'
        >
          <span 
            class='flag'
            :style="`background-image:url(/nuxt-assets/img/icons/flags/${language.code}.svg`"></span>
          <span>{{ language.name }}</span>
        </li>
      </ul>
    </div>

    <input
      type="email"
      :placeholder="`${content.email_placeholder}`" 
      :value="$store.state.email" 
      @input='$store.commit("UPDATE_EMAIL", $event.target.value)'>

    <input
      type="password"
      :placeholder="`${content.password_placeholder}`" 
      :value='$store.state.password'
      @input='$store.commit("UPDATE_PASSWORD", $event.target.value)'>

    <input
      type="submit"
      :value="`${content.cta.text}`"
      :style="buttonStyle"
      @click.prevent='validateForm'>

    <!-- Show errors, if any. -->
    <div 
      class="error" 
      v-html=$store.state.XHRresults.freetrialSignup.message
      v-if='$store.state.XHRresults.freetrialSignup.message'>      
    </div>

    <div class="gdpr_target"></div>
  </form>
</template>


<script>
  import { validateEmail, validateFreetrialPassword } from '~/modules/validator.js'
  import briteVerify from '~/modules/brite-verify.js'
  import { freeTrialError, briteVerifyError } from '~/modules/config/errors.js'
  import getDevice from '~/modules/detect-device.js'
  import content from  '~/data/airtable/components/NoCardTrialForm/index.yaml'  
 
  export default {
    props: ['buttonBg', 'buttonColor'],
    
    data () {
      return {     
        content, 

        // Passed as props, if any (optional).
        buttonStyle: null ,

        // Makes dropdown languages visible or invisible
        isDropdownVisible: false
      }
    },

    
    beforeMount () {    
     
      // If props were passed, overwrite the CSS
      this.buttonStyle = {
        color: this.buttonColor,
        background: this.buttonBg
      }

      
    },
    
    methods: {

      /*************************************
       * ADDED FOR A/B TEST
       *************************************/
      onLanguageDropdownClick () {        
        this.isDropdownVisible = !this.isDropdownVisible
      },

      onLanguageChange (e) {
        // Update our store with the langcode in case other components need it
        let code = e.target.dataset.code || e.target.value
      
        // IE10 doesn't support dataset
        if (typeof code == 'undefined' || !code) {
          code = (e.target || e.srcElement).getAttribute('data-code')
        }        
        this.$store.commit('UPDATE_LANGCODE', code)
      },
      /*************************************
       * END A/B TEST
       *************************************/

      /*
       * Validate form.
       * Here we validate only - form submission is actually done
       * when a language is selected, after email and password
       * validation     
       */

      async validateForm () {      
        if (! validateEmail(this.$store.state.email)) {
          this.$store.commit('SET_XHR_RESULT', {
            type: 'freetrialSignup',
            message: briteVerifyError[this.$store.state.locale].join()
          })
          // WS-4333 Amplitude - Account Creation Error Occurred          
          amplitude.getInstance().logEvent('Account Creation Error Occurred', {
            'Trial Length': '3 Days',
            'Billing Cycle': 'N/A',
            'Learning Language' : 'N/A',
            'Error Type': 'Email Validation Failed',
            'Error Step': 'Email and Password Entered'
          });
          return
        }

        if (! validateFreetrialPassword(this.$store.state.password)) {
          // WS-4333 Amplitude - Account Creation Error Occurred          
          amplitude.getInstance().logEvent('Account Creation Error Occurred', {
            'Trial Length': '3 Days',
            'Billing Cycle': 'N/A',
            'Learning Language' : 'N/A',
            'Error Type': 'Password Validation Failed',
            'Error Step': 'Email and Password Entered'
          });
          this.$store.commit('SET_XHR_RESULT', {
            type: 'freetrialSignup',
            message: freeTrialError[this.$store.state.locale].invalidPassword.join('')
          })
          return
        }

        // Amplitude - account creation started - WS-4333
        try {          
          amplitude.getInstance().logEvent('Account Creation Started',  {
            'Trial Length': '3 Days',
            'Billing Cycle': 'N/A',
            'Learning Language' : 'N/A'
          });
        } catch (e) {
          console.warn('Could not fire amplitude "Account Creation Started" event. Error below.')
          console.log(e)
        }
        
        // Failed briteverify check
        if (! await briteVerify(this.$store.state.email)) {    

          this.$store.commit('SET_XHR_RESULT', {
            type: 'freetrialSignup',
            message: briteVerifyError[this.$store.state.locale].join('')
          })

          // Emit signal for whatever components need it
          this.$bus.$emit('BRITEVERIFY_CHECK_PASSED', false)   

          // Amplitude - Account Creation Error Occurred          
          amplitude.getInstance().logEvent('Account Creation Error Occurred', {
            'Trial Length': '3 Days',
            'Billing Cycle': 'N/A',
            'Learning Language' : 'N/A',
            'Error Type': 'BriteVerify Validation Failed',
            'Error Step': 'Email and Password Entered'
          });

          return
        } else {
          console.log('BriteVerify: OK')
        }
        

        // If we're here, all validation (hopefully) passed

        // Clear Errors
        this.$store.commit('SET_XHR_RESULT', {
          type: 'freetrialSignup',
          message: ''
        })

        // WS-3651, WS-4333 - event 131 if briteverify passes
        try {
          // Adobe
          s.clearVars();
          s.addEvent('event131');
          s.tl(this,'o','event131');
          _satellite.track('nonBillableFreeTrialInitiatedPixels');

          // Amplitude - Account creation step completed          
          amplitude.getInstance().logEvent('Account Creation Step Completed', {
            'Trial Length': '3 Days',
            'Billing Cycle': 'N/A',
            'Learning Language' : 'N/A',
            'Step Name' : 'Email and Password Entered'
          });

        } catch (e) {
          console.warn('Could not fire event 131, or amplitude. Error below')
          console.log(e)
        }

        // Send email to EC
        this.sendEmailToEC()

        /********** EVENT HANDLING ***********/
        if ( ! 'abTest' in window) {
          this.$bus.$emit('BRITEVERIFY_CHECK_PASSED', true)
        }



        /*********************************************
         * A/B TEST code
         ********************************************/
        // WS-4333, WS-4206 - Event129 - when language is selected. 
        // Don't fire if user clicked 'see all languages'
        
        //TODO still needed?m ove to lang change then
        try {              
          amplitude.getInstance().logEvent('Learning Language Selected', {
            'Trial Length': '3 Days',
            'Billing Cycle': 'N/A',
            'Language' : this.$store.getters.selectedLanguage.name
          })
          
          s.clearVars();
          s.addEvent('event129');
          s.tl(this,'o','event129');
        } catch (e) {
          console.warn('Could not fire Event129 or Amplitude "Learning Language Selected". Error below.')
          console.log(e)
        }

        this.isLoading = true     

        let gdpr_consent_given = window.gdpr && window.gdpr.email_consent;
        
        // Data to send to provision for account creation
        let data = {
          email : this.$store.state.email,
          password: this.$store.state.password,
          trial_lang: this.$store.state.langcode,
          first_name : process.env.FREETRIAL_FIRST_NAME,
          language: process.env.FREETRIAL_LANGUAGE,
          site_code: process.env.FREETRIAL_SITE_CODE,
          guid: process.env.FREETRIAL_GUID,
          consent_type: gdpr_consent_given || null,
          country_code: gdpr.country_code || 'US',
          cid: this.$route.params.cid || ''
        }
        
        let req = null
        let error = null
        try {
          req = await this.$axios.$post(process.env.FREETRIAL_API + encodeURIComponent(JSON.stringify(data)))
        } catch (e) {
          error = 'Network error. Please try again.'
          this.isLoading = false
          return
        }
        
        // String comesback from server in a strange format      
        console.log('Attempting to parse: ')
        console.log(req)
        let response = JSON.parse(req.match(/\?\((.+)\)/)[1])                 
        let locale = this.$store.state.locale
        let errorCode = response.error

        console.log('Response from provision:')
        console.log(response)
        
        // Provision server sent back an error
        if (errorCode != 0) {
          try {
            error = freeTrialError[locale][errorCode].map(o => `<div>${o}</div>`).join('')
          } catch (e) {
            console.warn('Unknown error. Shown below:')
            console.log(e)
            error = "Unknown error. Please try again."
          }
        }
        

        if (error) {
          this.$store.commit('SET_XHR_RESULT', {
            type: 'freetrialSignup',
            message: error
          })

          
          this.isLoading = false

          // WS-4333 Capture error message
          try {
            s.clearVars();
            s.eVar52 = response.message || "N/A"
            s.tl();

            amplitude.getInstance().logEvent('Account Creation Error Occurred', {
              'Trial Length': '3 Days',
              'Billing Cycle': 'N/A',            
              'Learning Language': this.$store.getters.selectedLanguage.name,
              'Error Type': response.message,
              'Error Step': 'Learning Language Selected'
            });
          } catch (e) {
            console.warn('Could not set eVar52. Error below:')
            console.log(e)
          }
          return
        }

        /** If we're here, there were (hopefully) no errors **/


        try {                           
          // WS-4333 Amplitude Trial Started
          if (typeof response.license_guid != 'undefined') {
            amplitude.setUserId(response.license_guid)
          } 

          amplitude.getInstance().logEvent('Trial Started', {
            'Trial Length': '3 Days',
            'Billing Cycle': 'N/A',
            'Learning Language': this.$store.getters.selectedLanguage.name          
          });        
          
        }
        catch (e) {
          console.warn('Error firing Adobe Analytics or Amplitude. Error below')
          console.log(e)
        }

        try {
          // WS-3665 (eVar90), WS-4032 (eVar91)
          s.clearVars();
          s.eVar91 = code
          s.eVar90 = response.license_guid || 'N/A'
          s.tl(this);       

          // Adobe 130
          s.clearVars(); 
          s.addEvent('event130');
          s.tl(this); 
        } catch (e) {
          console.warn('Could not set evar91, evar90, or fire event 130. Error below:')
          console.log(e)
        }

              
        let redirectUrl = null
        
        // if Desktop - redirect to product
        // purchase=true lets product know to include DTM
        // https://jira.trstone.com/browse/TCOM-2024
        if (getDevice() == 'desktop') {
          // We can only log a user in if we have a token
          if (response.ls_token) {
            this.totaleUrl += `dtm_trial_type=nocc`
              + `&purchase=true`
              + `&target_language=${code.toUpperCase()}`
              + `&username=${this.$store.state.email}`
              + `&accepted_terms=true`
              + `&authToken=${response.ls_token}`
              + `&namespace=`          
          } else {
            // If we don't have a token, send them to login page with trial language
            this.totaleUrl = this.totaleUrl.replace('token_authentication', 'sign_in')
            this.totaleUrl += `&target_language=${code.toUpperCase()}`
          }

          redirectUrl = this.totaleUrl
        } else {
          // if mobile, redirect to app store
          redirectUrl =  '/lp/form-mobile-success'
        }              
      
        // Give a timeout to make sure pixels and tracking fire      
        console.log('redirecting to: '+ redirectUrl)
        window.setTimeout(function() {
          window.location.href = redirectUrl;
        },600);      
    








        
      },

      sendEmailToEC () {
        // More on EC here: https://jira.trstone.com/wiki/display/WDCMS/Liferay+CIS
        let formName = this.$store.state.locale == 'en' ? 'NOCC_TRIAL' : 'NOCC_TRIAL_ESPANOL'
        let data = {
          email : this.$store.state.email,
          cis_name : formName || '',
          website: 'US_WEBSITE',          
          demo_type : 'free_trial_signup',
          form_url : 'homepage',
          consent_type : ( window.gdpr && window.gdpr.email_consent ) || "unknown",
          visit_country_code : ( window.gdpr && window.gdpr.country_code ) || "unknown",
          newsletter_type : "homepage_trial",
          //cid : _satellite.getVar("mostrecentcampaign")
        }

        let url = (window.location.href.search(/(\.stg\.)|(local)/i)>-1 ? 'https://www.stg' :'https://www')
			  //+ '.rosettastone.com/?redirect2mobile=no&p_p_id=rosettaajaxsubmit_WAR_rosettaajaxsubmitportlet&p_p_lifecycle=2';
        + '.rosettastone.com/?redirect2mobile=no&p_p_id=rosettaajaxsubmit_WAR_rosettaajaxsubmitportlet&p_p_lifecycle=2&';
        
        //url += encodeURIComponent(JSON.stringify(data))
			  url += Object.keys(data).map(o => `${o}=${data[o]}` ).join('&')  

        this.$axios.post(url).then( res => {} )
        
      }
    }
  }
</script>

<style lang="stylus" scoped>
  form
    display flex
    flex-direction column
  .language-select
    background #fff
    text-align left
    box-sizing border-box
    margin-bottom 1.4em
    border-radius 6px
    font-weight 100
    border 1px solid #999
    position relative
    .selected-language
      padding 0 //5px 0 5px 20px
      padding 12px
      display flex
      align-items center
      font-size 95%
    ul
      position absolute
      background inherit
      width 100%
      left -1px
      top 39px
      max-height 256px
      border 1px solid #999
      border-top none
      overflow-y scroll
    ul::-webkit-scrollbar-track            
      border-radius 3px
    ul::-webkit-scrollbar
	    width 8px    
    ul::-webkit-scrollbar-thumb
	    border-radius 10px	    
	    background-color #555         
    li
      list-style none      
      padding 10px
      box-sizing border-box
      cursor pointer
      margin-right 2px
      background-repeat no-repeat
      display flex
      font-size 95%      
      &:hover
        background #eee
      & *
       pointer-events none
    span.flag
      height 14px
      width 22px
      display inline-block
      background-size 100% 100%
      margin-right 7px
   
      
      
  input
    padding 12px
    font-weight 100
    border 1px solid #999
    border-radius 6px
    margin-bottom 15px
    box-sizing border-box
    margin-bottom 1.4em
  input[type=submit]
    background #363534
    color #fff
    display block
    font-size 16px    
    letter-spacing 3px
    font-family effra
    text-align center
    border-radius 6px
    padding 1.3em 2em
    font-weight bold
    border none
    margin-bottom 0
  .error
    padding 0.8em
    font-weight 400
    margin-top 5px
    background #d89ba6 // #bf6b6b
    color #882727
    letter-spacing 1px
    text-align left
    line-height 22px
    border 1px dashed red
    font-weight 100
    & >>> .error-head
      font-weight bold
      color #fff
      margin-bottom 5px
      
    
</style>