Unable to set apiKey outside of index.html


Posted on
Mar 01 2016


I'm trying to initialise raygun after our app has finished loading, e.g. outside of index.html.

After the app has loaded, rg4js('apiKey', {{apiKey}}) appears to get called properly, but no errors are being posted.

If I call it from within index.html with a hardcoded apikey, it will work fine. If I call it with one apiKey in index.html, then call again later with another apiKey, errors are still getting posted through to the dashboard associated with the first apiKey.

We have used this exact method in another app, so I can't see why it's not working in this case. Any ideas?

Code in index.html:

h&&h(b,c,d,f,g),g||(g=new Error(b)),a[e].q=a[e].q||[],a[e].q.push({

    rg4js('apiKey', 'api_key_1');
    rg4js('attach', true);
    rg4js('disablePulse', true);
    rg4js('enableCrashReporting', true);
    rg4js('saveIfOffline', true);
    rg4js('setVersion', '0.0.0');
    rg4js('options', {
        allowInsecureSubmissions: true,
        debugMode: true

Called later (after our config has loaded): rg4js('apiKey', config.raygun.apiKey);

Deleted User

Posted on
Dec 27 2016

Hello Simon!

My first thoughts would be that you're not calling the second rg4js('apiKey', {{apiKey}}) on a new Raygun object. Only one Raygun object can be attached as the window.onerror handler at one time, as onerror can only be bound to one function at once. Whichever Raygun object had attach() called on it last will handle the unhandle errors for the page.

Without actually seeing the code for the page I would wager that just calling the rg4js() again isn't overwriting the first api key so all the automatic errors are going to the first api key's application.

Are you creating a new Raygun object in the other application where this is working currently?

Jesse, Developer Evangelist