Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from zarathustra323/rapid-identify-vue
Browse files Browse the repository at this point in the history
Send IdentityX+Omeda IDs to `Olytics.confirm`
  • Loading branch information
zarathustra323 authored Apr 14, 2021
2 parents c7ea81d + 924e95a commit 7fd6f44
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/marko-web-omeda-identity-x/browser/.eslintrc.js
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 packages/marko-web-omeda-identity-x/browser/rapid-identify.vue
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>

0 comments on commit 7fd6f44

Please sign in to comment.