This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from zarathustra323/rapid-identify-vue
Send IdentityX+Omeda IDs to `Olytics.confirm`
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
extends: [ | ||
'airbnb-base', | ||
'plugin:vue/recommended', | ||
], | ||
env: { | ||
browser: true, | ||
}, | ||
rules: { | ||
'vue/max-attributes-per-line': ['error', { | ||
singleline: 3, | ||
multiline: { | ||
max: 1, | ||
allowFirstLine: false, | ||
}, | ||
}], | ||
}, | ||
}; |
81 changes: 81 additions & 0 deletions
81
packages/marko-web-omeda-identity-x/browser/rapid-identify.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<template> | ||
<div class="omeda-rapid-identity-x" style="display: none;" /> | ||
</template> | ||
|
||
<script> | ||
const { warn } = console; | ||
export default { | ||
props: { | ||
endpoint: { | ||
type: String, | ||
default: '/__idx/omeda-rapid-ident', | ||
}, | ||
olyticsCookieName: { | ||
type: String, | ||
default: 'oly_enc_id', | ||
}, | ||
idxCookieName: { | ||
type: String, | ||
default: '__idx', | ||
}, | ||
}, | ||
data: () => ({ | ||
cookies: null, | ||
}), | ||
computed: { | ||
hasIdentityXUser() { | ||
return Boolean(this.cookies[this.idxCookieName]); | ||
}, | ||
encryptedId() { | ||
const id = this.cookies[this.olyticsCookieName]; | ||
// the encrypted ID cookie value is enclosed with double-quotes. remove. | ||
return id ? id.replace(/"/g, '') : null; | ||
}, | ||
}, | ||
created() { | ||
this.parseCookies(); | ||
this.rapidIdentify(); | ||
}, | ||
methods: { | ||
async rapidIdentify() { | ||
if (this.hasIdentityXUser) { | ||
const res = await fetch(this.endpoint, { method: 'GET' }); | ||
const { encryptedId } = await res.json(); | ||
if (encryptedId) this.$emit('encrypted-id-found', encryptedId); | ||
if (encryptedId && encryptedId !== this.encryptedId) { | ||
// run olytics confirm to set the IdentityX user's omeda ID. | ||
const { olytics } = window; | ||
if (olytics) { | ||
olytics.confirm(encryptedId); | ||
} else { | ||
warn('Unable to identify IdentityX user: no olytics instance was found.'); | ||
} | ||
} | ||
} | ||
}, | ||
parseCookies() { | ||
if (!this.cookies) { | ||
this.cookies = document.cookie.split(';').reduce((o, pairs) => { | ||
const [key, value] = pairs.trim().split('=').map(v => decodeURIComponent(v)); | ||
let v; | ||
switch (value) { | ||
case 'null': v = null; break; | ||
case 'true': v = true; break; | ||
case 'false': v = false; break; | ||
case 'undefined': v = undefined; break; | ||
default: v = value; | ||
} | ||
return { ...o, [key]: v }; | ||
}, {}); | ||
} | ||
return this.cookies; | ||
}, | ||
}, | ||
}; | ||
</script> |