Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cookie data from one website, get the updated data on the other website #1

Closed
mhulet opened this issue Aug 24, 2016 · 2 comments

Comments

@mhulet
Copy link

mhulet commented Aug 24, 2016

I did the set up yesterday and it works fine. I'm now sharing user data between websites, which is absolutely amazing :) Kudos to @ecaroth!

There is still something I didn't succeed to achieve. My first use case is about sharing data between an online store and its knowledge base. This way, we can see which customers are actually using the knowledge base. It works well but sometimes, customer data would be updated on the online store. Here is the data I'm writing in the cookie:

<script type="text/javascript" src="//app.helpman.io/xdomain_cookie.js"></script>
<script type="text/javascript">
    var helpman_cookie = xDomainCookie('//app.helpman.io');
    var customer_data = {
      "distinct_id": "{{ customer.id }}",
      "name": "{{ customer.name }}",
      "email": "{{ customer.email }}",
      "custom_fields": {
        "lifetime_spent": "{{ customer.lifetime_spent }}",
        "last_order": "{{ customer.last_order.created_at }}",
        "tags": "{% for tag in customer.tags %}{{ tag }} {% endfor %}"
      }
    };
    helpman_cookie.set('helpman_petitkiwi', JSON.stringify(customer_data));
</script>

I'm interested to share key data about each customer, that's what I put in custom_fields. This data will be updated regularly.

But actually the cookie data is not shown as updated on the knowledge base side. I suspect local storage to be the culprit, but I don't see the cookie stored locally using the Chrome development tools.

Any idea?

@ecaroth
Copy link
Contributor

ecaroth commented Aug 25, 2016

@mhulet - From what I am understanding, your app is setting the customer_data object, which is periodically updated, and then the knowledge base is just reading the object. What I think is happening is that the knowledge base is using the cached local cookie, which will possibly contain a stale value of the data (but return faster).

To fix the issue, you should use xdomain_only=true for the xDomainCookie setup in the knowledge base, so it doesn't use a local cached version of the cookie and will always read the most recent from the shared cookie. I just updated the readme to contain more info on this (see the section Cross Domain ONLY Cookies, which goes into more detail.

Also, as a note - just bumped the version to 1.0.4, which contains some security updates and a few small bugfixes. The last version (1.0.3) should still work for you, but I encourage you to update to 1.0.4 if you can. Thanks!

@mhulet
Copy link
Author

mhulet commented Aug 26, 2016

Great! Works perfectly, thanks for the documentation too. This is definitely useful for sharing JSON-encoded data about a user.

I have updated to 1.0.4. Will keep an eye on the coming updates. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants