0

The task of this app is to identify a URL ( refferer link) and to replace the telephone number or an image inside the site with another phone number or image . For example, if a person enters our site from site A , replace the phone number that is on our site to X , and if one enters our site from site B, replace the phone number on our site to Y . My code is as follows but it doesn’t work. Please guide me.

install.json

{
"resources": {
    "body": [{
        "type": "script",
        "src": "./app.js"
    }]
},
    "options": {
        "properties": {
            "referrer": {
                "order": 1,
                "type": "string",
                "title": "The refferer url : "
            },
            "text": {
                "order" : 2,
                "type": "string",
                "title": "Enter the phone number you want to replace",
                "products": ["plus", "pro"]
            },
            "location": {
                "title": "Location",
                "description": "Select the part of your page which contains a Text ( for example : phone number) you’d like to change",
                "type": "object",
                "format": "element",
                "default": {
                    "selector": "body",
                    "method": "prepend"
                  },
                "order": 1
            },
            "slides": {
                "title": "Slides",
                "type": "array",
                "maxItems": 10,
                "order": 2,
                "items": {
                  "type": "object",
                  "title": "Slide",
                  "properties": {
                    "image": {
                      "title": "Image",
                      "type": "string",
                      "order": 1,
                      "format": "image"
                    },
                    "description": {
                      "title": "Description",
                      "description": "This text is used as the image’s title and alt text, important for SEO.",
                      "default": "A wonderful image portraying a better future.",
                      "order": 2,
                      "type": "string",
                      "maxLength": 200
                    }
            }
        }
    }
        }       
    }

app.js

(function () {
'use strict'

var options = INSTALL_OPTIONS
var element

if (document.referrer.trim() == option.refferer.trim()) {

function updateElements () {
 element = INSTALL.createElement(options.location, element);
    if (!element) return
    element.textContent = options.text;
 }

}
}())
nibble
  • 384
  • 3
  • 12
amirdehghan
  • 1,601
  • 2
  • 7
  • 4

1 Answers1

0

If it's only for your own site, a Cloudflare app isn't the answer. Use a Cloudflare worker on your site instead.

The Cloudflare worker could save the referrer in a cookie the first time the user goes to your site, and then show the appropriate phone number

Aaron Queenan
  • 851
  • 8
  • 14