Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End If/Else statement, different analytics code depending on URL

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27129
    vitug
    Member

    Thanks ahead of time for help on this topic. I’ve searched through the forum, and couldn’t find anything similar, so forgive me and point me in the right direction if there’s an answer.

    I’m trying to right a php if/ else statement that needs to go in between the <head> tags of the main template page.
    Depending on the URL, I need different analytics code to be shown in the header to run javascript to track conversions.

    Example:

    If it’s this url, http://test.tester.local/customer, run this analytics code:

    <SCRIPT language="JavaScript" type="text/javascript">
    <!– Yahoo! Inc.
    // Event Type ID: 1
    // Segment Type ID: 0
    if (typeof(window.ysm_customData) != ‘object’) window.ysm_customData = new Object();
    window.ysm_customData.segment_1SE66WWWWP06H0 = "event=0,transId=,currency=,amount=";
    // –>
    </SCRIPT>

    else if it’s this url, http://test.tester.local/documents, run this analytics code:

    <SCRIPT language="JavaScript" type="text/javascript">
    <!– Yahoo! Inc.
    // Event Type ID: 1
    // Segment Type ID: 0
    if (typeof(window.ysm_customData) != ‘object’) window.ysm_customData = new Object();
    window.ysm_customData.segment_1SE66WP06H0 = "event=0,transId=,currency=,amount=";
    // –>
    </SCRIPT>

    else if it’s this url, http://test.tester.local/quote, run this analytics code:

    <SCRIPT language="JavaScript" type="text/javascript">
    <!– Yahoo! Inc.
    // Event Type ID: 1
    // Segment Type ID: 0
    if (typeof(window.ysm_customData) != ‘object’) window.ysm_customData = new Object();
    window.ysm_customData.segment_1SE66WP06H0 = "event=0,transId=,currency=,amount=";
    // –>
    </SCRIPT>

    I hope this was clear. Thanks again for any help.

    #67854
    JaredAM
    Member

    There are a lot of different ways of doing this. PHP_SELF would be pretty safe for this:

    Code:
    $mypath = $_SERVER[“PHP_SELF”];

    if (substr_count($mypath, “customer”) > 0) { // Catch customer

    } elseif (substr_count($mypath, “documents”) > 0){ // Catch documents

    } else { // Catch all

    }

    #67857
    vitug
    Member

    Thank you for taking the time to respond JaredAM.

    I have one problem that I’m sure is all syntax. The (3) specific urls that I’m targeting are these:

    http://test.tester.local/customer (Home Page)
    http://test.tester.local/customer/auto/va/quote (Quote Page)
    http://test.tester.local/customer/auto/va/documents (Documents Page)

    The problem that I’m finding is that all (3) urls have at least this text:
    http://test.tester.local/customer

    So the if/else statement is negating the other pieces of analytics, and using only the one piece of analytics assigned to the home page (http://test.tester.local/customer)

    Is this an easy fix in the if/else statement?

    #67860
    JaredAM
    Member

    Humm, with that tree, PHP_SELF will still work, but you’ll have to rearrange the if/elses or else customer would be caught right off the bat.

    Code:
    $mypath = $_SERVER[“PHP_SELF”];

    if (substr_count($mypath, “documents”) > 0) { // Catch documents

    } elseif (substr_count($mypath, “quote”) > 0){ // Catch quote

    } else { // Catch all (customer)

    }

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.