#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    uk
    Posts
    120
    Rep Power
    15

    Fire Facebook Pixel When Page is Redirected


    I have some code which someone wrote, which is set to fire a facebook pixel (tracking code) when someone clicks a button.

    Is there a way to modify this code so that if someone was automatically redirected to another page (without having to click a button), the Facebook pixel code will still fire.

    With the original button related code, the button also had to have some CSS inside it which said...
    Code:
    cf-fb-fire-InitiateCheckout
    The Facebook pixel code is pasted in the head section of the page.
    The Facebook event code is pasted in the body section of the page.

    The Javascript code shown here is pasted in the footer section of the code.
    Code:
    <script> 
    $(function () { 
        $(document).on('click’, '[data-title*=“cf-fb-fire-“]’, function (ev) {
            var titleParts = $(this).attr('data-title’).split('’);
            var fbEvent = null;
            var fbEventVal = null;
            var fbEventCurrency = null;
            $.each(titleParts, function (index, value) {
                if (value.indexOf('cb-fb-fire-') > -1) {
                    var valArr = value.split('-');
                    fbEvent = valArr[3];
                    if (valArr.length > 4) {
                        fbEventVal = valArr[4];
                        fbEventCurrency = varArr[5] || 'USD’;
                    }
                    return false;
                }
            });
            if (fbEvent && fbEventVal) {
                fbq(’track’, fbEvent, {value: fbEventVal, currency: fbEventCurrency});
            } else if (fbEvent) {
                fbq(’track’, fbEvent);
            } 
        }); 
    }); 
    </script>
    So what could be the new code for pasting the footer section and in the css for the redirect?

    Appreciate the help,

    JH
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
    That code depends on knowing an event, something only possible if the user clicked a button. Do you have an event to use for if they navigate away for some other reason?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    uk
    Posts
    120
    Rep Power
    15
    Originally Posted by requinix
    That code depends on knowing an event, something only possible if the user clicked a button. Do you have an event to use for if they navigate away for some other reason?
    The user goes through a quiz. After answering the last question, they will be redirected to an affiliate link.

    So as they are being redirected, I'd like to drop a pixel to know that that have made it through the quiz and has been redirected to the offer page.

    Any way to do that?

    JH
  6. #4
  7. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
    But... the user has to click a button to do that, right? So why not just put the "pixel" in that button?

    Anyway yes, you can, but like I said there has to be a certain event for the "pixel" to use. Like the button you first mentioned, its event was InitiateCheckout. Do you have an event for this "pixel" to use?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    uk
    Posts
    120
    Rep Power
    15
    Originally Posted by requinix
    But... the user has to click a button to do that, right? So why not just put the "pixel" in that button?

    Anyway yes, you can, but like I said there has to be a certain event for the "pixel" to use. Like the button you first mentioned, its event was InitiateCheckout. Do you have an event for this "pixel" to use?
    Naa, there is no button.

    The Quiz asks questions and the user just selects the answer, which then immediately loads the next question. There is no button.
    After the final question is answered, it redirects to a URL.

    This is all done via Clickfunnels which is a platform. So I can only put certain things in certain places.

    JH
  10. #6
  11. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
    Still, going to need that event name. When you have it, you can put code onto the page that fires it when the user navigates away, but that would apply whether they answer the question or close the tab. Better would be to make it fire when the answer is selected, which would require some knowledge about how that works.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Location
    uk
    Posts
    120
    Rep Power
    15
    Originally Posted by requinix
    Still, going to need that event name.
    When I go to the settings of the quiz and redirect it says this:
    Screenshot 2019-02-25 at 12.30.38.png

    And when I go to the CSS button for the quiz, it shows me this:
    Screenshot 2019-02-25 at 12.31.14.png

    I have edited the top part (for a button click) but I need to edit it so that it works with redirect.

    Any ideas from these images?

    JH
  14. #8
  15. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
    I'm not sure you can. Are you sure it's possible for you to embed arbitrary Javascript into these pages? What do you have available for the FB Pixel and GTM settings?

IMN logo majestic logo threadwatch logo seochat tools logo