CallRail marketing integration for Wix loads the CallRail swap.js file on all pages. How can I reference and call functions in this file in Wix Code?
Update - following examples I have now created a backend swap.js file where I fetch the external js file
import {fetch} from ‘wix-fetch’;
export function swap() {
const url = “https://cdn.callrail.com/companies/[companyid]/[APIkey]/12/swap.js”;
const request = {
“method”: “get”,
“Content-type”: “text/javascript”
};
return fetch(url, request)
}
(no error handling yet)
The intention is to create a backend jsw file to export the function I need from the swap.js file
import {swap} from ‘backend/swap’;
export function swapthem () {
return swap();
}
The problem is that I don’t have the javascript knowledge to know how to reference / export / call a single function from the swap.js file
Simon, that is not going to work. “Get”-ing it with fetch does not register the .js file, it will be treated as a pointless string.
Things that I would try (in any particular order):
- try to eval() the string and see if you can call its functions (doubt it). See w3schools.com for eval()
- try putting the swap.js into header or body thru Editor: Settings:Tracking tools and analysis
- try the same by simply copying the content of the whole swap.js into the header or body
- copy swap.js file into a public wix js file and fidlle till it works, call it from site level, not page in the editor
- use html-component on every page and communicate with it thru you Wix Page.
All solutions (except 5) depend on 1 thing: that the swap.js file doens´t access the DOM. If it does, you are out of luck.
Well, you got your work cut out for you for this weekend. Good luck.
Thanks Giri. As the whole point of swap.js is to swap out telephone numbers after the page has loaded I guess that it needs to access the DOM. I’ll give solution 5 a try
Hi Simon: There are some instructions on the callrail website that discusses use of this cdn api right here:
https://support.callrail.com/hc/en-us/articles/201051406
Can I use dynamic number insertion on my Wix site?
If you are on any of Wix’s premium plans , you can install CallRail’s swap script in Google Tag Manager, and add Google Tag Manager to your Wix site.
Use this article to learn how to add dynamic number insertion to Google Tag Manager .
Use these Wix instructions to learn how to add Google Tag Manager to your premium Wix site .
Hope this helps!
@stevesoftwareservice Thanks but unfortunately these integrations do not work 100%. There are issues when the user changes page and issues when the user revisits the landing page in the same session (numbers are not swapped out). There are different results depending on whether or not the number is in the page header or body (design wise). CallRail and Wix were poor in support. Quite frankly the integration should be removed as an option unless it works as advertised. In the end I went with Call Tracking Metrics whose solution does work out of the box, albeit that the swap out is a little delayed.
@simonthomas Of course now Wix has added CallRail support into the Marketing Integrations options