Load External Java Library | XM Community
Skip to main content

Hi, I plan to collect device information from the anonymous survey link. Meta Info cannot work when using the anonymous link. Therefore, I tried to load the ua-parser java library (Here is the package link: https://github.com/faisalman/ua-parser-js/tree/gh-pages) into Qualtrics JavaScript.

 

However, the function doesn’t work. How to set up the external JS library work? I am a beginner in JavaScript. Below is my code. I appreciate any help.

 

Qualtrics.SurveyEngine.addOnReady(function()
{
    /*Place your JavaScript here to run when the page is fully displayed*/
     jQuery.getScript("https://github.com/faisalman/ua-parser-js.git", function(){
    
         //src = "https://github.com/faisalman/ua-parser-js.git";     
        //src="https://cdnjs.cloudflare.com/ajax/libs/ua-parser-js/0.7.28/ua-parser.min.js";
        
         // Create an instance of UAParser
        var parser = new UAParser();
        // Parse the user agent string
        var result = parser.getResult();
         
        
        // Access parsed information
        var deviceModel = result.device.model || "Unknown";
        var deviceType = result.device.type || "Unknown";
        var browserName = result.browser.name || "Unknown";
        var browserVersion = result.browser.version || "Unknown";
        var osSystem = result.os.name || "Unknown";
        
        Qualtrics.SurveyEngine.setJSEmbeddedData("DeviceModel", deviceModel);
        Qualtrics.SurveyEngine.setJSEmbeddedData("DeviceType",deviceType);
        Qualtrics.SurveyEngine.setJSEmbeddedData("BrowserName", browserName);
        Qualtrics.SurveyEngine.setJSEmbeddedData("BrowserVersion", browserVersion);
        Qualtrics.SurveyEngine.setJSEmbeddedData("OperatingSystem", osSystem);
    });

});

 

@Lizy Please paste the code so someone can replicate the problem. We can only debug with naked eyes with code picture like this


@Lizy Please paste the code so someone can replicate the problem. We can only debug with naked eyes with code picture like this

Thank you so much for your reminder.


@Lizy The correct link is https://unpkg.com/ua-parser-js@0.7.31/dist/ua-parser.min.js

Replace it in your code, you won’t get 404 not found anymore in console log

 


@Lizy The correct link is https://unpkg.com/ua-parser-js@0.7.31/dist/ua-parser.min.js

Replace it in your code, you won’t get 404 not found anymore in console log

 

Hi @dxconnamnguyen THANK YOU so much for your help! It works. You’re brilliant. Thank you for saving me.


@Lizy Happy to help 👍


Leave a Reply