1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Please Help!

Discussion in 'Programming' started by Saidbenssi, Oct 29, 2019.

  1. #1
    Saidbenssi, Oct 29, 2019 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #2
    A plugin would depend on your CMS. You haven't posted in the WordPress section so I'm guessing you're using something else.

    Essentially these are the steps:
    • A page is requested
    • Get referrer info
      • Is it an external page? set a cookie true/false
      • Internal page? don't change the cookie
    • Content is generated, check the cookie, show/hide the info
    Is the content always the same if the user is referred by facebook? Something like a like/share button? or will there be a section of completely different text?

    These days I know WP better than any other CMS so you'd need a plugin that either enables/disables the functionality, points to the appropriate widget, creates the widget, and if necessary adds a text box to the post/page editor, and then on the site make the appropriate changes to the page.

    It wouldn't be hard, and yes, someone probably has already done something like this.
     
    sarahk, Oct 29, 2019 IP
    Saidbenssi likes this.
  3. Andrii Ozemko

    Andrii Ozemko Member

    Messages:
    79
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    33
    #3
    I would recommend to do it with JavaScript. You can parse your request string (url), and decide what you need. But to implement it you need some basic JavaScript skills.
    To check if url contains specific parameter and hide something you can use code like this

    function hideSomeBlocksOnThePage() {
      let source=getUrlParameter(urlParameterSource); // 'utm_source' for example
      if (source==='facebook') {
      document.getElementById('text').style.display='none';
      }
      }
    
      function getUrlParameter(name) {
      name=name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
      var regex=new RegExp('[\\?&]'+name+'=([^&#]*)');
      var results=regex.exec(location.search);
      return results===null?'':decodeURIComponent(results[1].replace(/\+/g, ' '));
      };
    Code (javascript):
     
    Andrii Ozemko, Oct 29, 2019 IP
    Saidbenssi likes this.
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #4
    Note that @Andrii Ozemko's code only works on the first page opened. Any subsequent pages will be facebook-blind unless you save a cookie and check for that
     
    sarahk, Oct 29, 2019 IP
    JEET likes this.
  5. Andrii Ozemko

    Andrii Ozemko Member

    Messages:
    79
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    33
    #5
    Correct. Good point. Thanks. One point about cookies. If you save the 'source' to cookies and user opens page directly, they will see the same content for 'Facebook users'. Again, if user then come from Linkedin for example, they will see content for 'Linkedin users' when open page directly.
     
    Andrii Ozemko, Oct 29, 2019 IP
    JEET likes this.
  6. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #6
    Thinking about it, javascript would be a better solution for this.
    Because with PHP etc, you will need to parse the whole article also and then show parts of it, or store multiple copies of the same article. One for regular user, others for different refers.
    This could become very confusing depending on how many refers you wish to track.
    But with javascript, you simply hide a DIV tag.

    You should use a cookie like sarahk said.
    To avoid the problem mentioned by Andrii Ozemko of people opening the page directly, you can set the cookie for a short time, like for 10 minutes.
    After 10 minutes, if the user opens the webpage via a bookmark, then they will see the regular article.


    Do you by any chance want this for search engine bots?
    In that case, you will definitely need a PHP code. JavaScript solution is of no use there...
     
    JEET, Oct 30, 2019 IP