Home » Javascript » Linkedin JavaScript SDK SDK: Cannot read property 'Function' of undefined

Linkedin JavaScript SDK SDK: Cannot read property 'Function' of undefined

Posted by: admin November 1, 2017 Leave a comment

Questions:

I am initializing the JavaScript API and most of the time it gives me a Cannot read property 'Function' of undefined. I don’t know if this helps but it is on the lines calling this code.

Sslac.Function("IN.$Tag",function(b,a){a=a||document;

One thing I discovered, even though it says in the docs that the lang argument is not required that it would error on lang being undefined. I tried to do the same thing with onLoad but I am still getting the error.

I am using React and we are using server side rendering. I did add a the NoSSR package to see if that would fix it but it still does not.

Below is the code I am using to setup the SDK.

     <Head>
      <script
        type="text/javascript"
        src="//platform.linkedin.com/in.js"
        dangerouslySetInnerHTML={{ __html: `
          api_key: [API_KEY]
          lang: en_US
        ` }}
      />
    </Head>

Another thing to note is I did try this solution as well with the same results.

Update

This has to be a SSR thing. I can create the exact same app in create-react-app and in Nextjs, create-react-app is all ran client side, next is server side. Create-react-app works fine.

Here is the link to the magic for NextJS.
https://github.com/rileybracken/linkedin-test-next/blob/master/pages/index.js

Here is the link to the magic for Create React App.
https://github.com/rileybracken/linkedin-test-create-react-app/blob/master/src/App.js

Answers:

Ok not that this solves the problem but I had to put a onLoad argument in. I said that I did this before, but I had to do it in front of the script that initializes the JavaScript SDK.

I don’t know if it is a SSR specific issue, a React issue or that the Linkedin JavaScript SDK docs are not correct. But this works for now.

    <Head>
      <script dangerouslySetInnerHTML={{ __html: 'function liInit() { return null; }' }} />
      <script
        type="text/javascript"
        src="//platform.linkedin.com/in.js"
        dangerouslySetInnerHTML={{ __html: `
          api_key: [API_KEY]
          lang: en_US
          onLoad: liInit
        ` }}
      />
    </Head>

I am not going to accept this as the final answer since the documentation is off and this is more of a hack to get it to work.