Load External Java Library | XM Community
Skip to main content
Solved

Load External Java Library

  • October 11, 2023
  • 5 replies
  • 118 views

Forum|alt.badge.img+1
  • Level 1 ●
  • 5 replies

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);
    });

});

 

Best answer by Nam Nguyen

@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

 

5 replies

Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • October 11, 2023

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


Forum|alt.badge.img+1
  • Author
  • Level 1 ●
  • 5 replies
  • October 11, 2023

@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.


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • Answer
  • October 11, 2023

@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

 


Forum|alt.badge.img+1
  • Author
  • Level 1 ●
  • 5 replies
  • October 12, 2023

@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.


Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • October 13, 2023

@Lizy Happy to help 👍