How do I send variable data to a custom code script

Hello there,

I am trying to install Intercom into my weweb app, when I do this it works until I want to send Intercom a users ID, name and email. Below is the part of the script where I need to display my variables but I am not sure how to do this:

I have tried using the variable name, variable ID using wwLib ( name: wwLib.wwVariable.getValue(‘a6a7935f-6662-42fb-92aa-666f48cf9a3a’), ) but it doesn’t work. When trying wwLib in the console it says ‘ww Lib is not defined’ but if I manually enter wwLib.wwVariable.getValue(‘a6a7935f-6662-42fb-92aa-666f48cf9a3a’) into the web console it returns the expected value…

Please help!

Looks like you’re doing the code close to right, so now I wonder about the context in which you are adding the JS. If you’re still stuck, can you add a loom showing how you’re doing it?

I also made a vid a while ago about interacting with variables and JS in weweb, in which I make live code that works. Maybe the action shots give some hints on this too?

Hey Ray,

Thanks for this, I am not able to record a Loom right now but can do if what I am about to say doesn’t make sense.

I am adding the following code to the body of Custom Code:

This should then make the widget appear on each page as it does if I exclude the name, user_id, email and created_at but it does not show. Do I perhaps need to define the variables in the custom code before doing this?

Thanks a lot
Ed

Hi, there’s no code in your post - could you try re-pasting it into a code block? And when you say “custom code” - where is the code loaded? In a custom javascript action? In the page custom header? in the project header? specifics help, which is one reason the loom is such a shortcut - it’s specific and fast compared to this back-end-forth.

Apologies, here is the code block:

<script>
    window.intercomSettings = {
        api_base: "https://api-iam.intercom.io",
        app_id: "lcopzjye",
        name: wwLib.wwVariable.getValue('a6a7935f-6662-42fb-92aa-666f48cf9a3a'),
        user_id: wwLib.wwVariable.getValue('324073bd-6f2a-4711-b842-8ca9ddcc4ccf'),
        email: wwLib.wwVariable.getValue('6ff04dd1-3bcf-4614-a46a-950c6088958e'),
        created_at: wwLib.wwVariable.getValue('11bbcb97-eae4-4f75-8617-205162b0f9f7')
    };
</script>

<script>
    // We pre-filled your app ID in the widget URL: 'https://widget.intercom.io/widget/lcopzjye'
    (function() {
        var w = window;
        var ic = w.Intercom;
        if (typeof ic === "function") {
            ic('reattach_activator');
            ic('update', w.intercomSettings);
        } else {
            var d = document;
            var i = function() { i.c(arguments); };
            i.q = [];
            i.c = function(args) { i.q.push(args); };
            w.Intercom = i;
            var l = function() {
                var s = d.createElement('script');
                s.type = 'text/javascript';
                s.async = true;
                s.src = 'https://widget.intercom.io/widget/lcopzjye';
                var x = d.getElementsByTagName('script')[0];
                x.parentNode.insertBefore(s, x);
            };
            if (document.readyState === 'complete') {
                l();
            } else if (w.attachEvent) {
                w.attachEvent('onload', l);
            } else {
                w.addEventListener('load', l, false);
            }
        }
    })();
</script>

In Weweb there is an area called Custom Code accessed from the ‘More’ button and then selecting ‘Custom Code’. This has been posted in the body of that area. I have added a screenshot below:

Thanks!