ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Google E-Commerce - Assigining Variables question

October 28, 2008 1:28am

Subscribe [2]
  • #1 / Oct 28, 2008 1:28am

    ussher

    14 posts

    Hi im very new to expression engine.

    im trying to get google analytics e-commerce setup.

    When a booking is completed on my site the values of the booking are displayed:

    CODE IN BOOKING TEMPLATE:

    Booking Confirmation Number: {entry_id}
    
    
    {assign_variable:google1="this is google 1"}
    {assign_variable:google2={entry_id}}
    
    {embed="site/footer"}

    results in this being displayed as output:
    {assign_variable:google2=10050}

    So it looks like the first variable IS being assigned, but the second is not.

    I want to get the {entry_id} variable available to me in the footer template.  Currently it is not available.

    CODE IN FOOTER TEMPLATE

    g1:{google1}
    g2:{google2}
    entry_id:{entry_id}

    results in this being displayed as output:
    g1:{google1} g2:{google2} entry_id:{entry_id}

    Google E-Commerce requires that the ecommerce section be called AFTER the main google code, The main google code is in the footer.  This is why i need these variables availabe to me in the footer too.

    So the question is: How can i get a variable that is available in the booking page assigned to another variable that is available in the footer?
    Thanks very much.

  • #2 / Oct 28, 2008 4:05am

    ussher

    14 posts

    Im getting closer:
    http://expressionengine.com/docs/templates/globals/assign_variable.html

    That page outlines how to assign a variable, but it also says:

    Assigned Variables act as a straight string replacement for use later in the same template.

    But doesn’t give a clue as to where to go next?
    (I expected the footer, being included, would be in the same scope. So variables would be available but they aren’t.)

    im kinda lost.  any help would be appreciated. Thanks

  • #3 / Oct 28, 2008 5:16am

    pushloop

    422 posts

    Hmm, I don’t think you can use an assigned variable in an embedded template. What you could do I think, is to pass it through to the embedded template using embed variables.

    However, as described in the docs “Variable assignment and replacement occurs instantly when the template is loaded and may not be affected by the result of another tag’s output.”
    I believe this means that you won’t be able to assign a variable with “{entry_id}”.

    However, if you do want to pass the entry_id to an embedded template you can do this as long as the embedded template sits within a weblog entries tag.

    {assign_variable:google1="this is google 1"}
    
    {exp:weblog:entries}
    {embed="site/footer" foo="{google1}" moo="{entry_id}"}
    {/exp:weblog:entries}

    This should enable you to call “{foo}” within your embedded template to render “this is google 1”, and “{moo}” to render the entry_id, like this:

    {embed:foo}
    {embed:moo}
  • #4 / Oct 28, 2008 5:30am

    ussher

    14 posts

    First of all, Thanks for your help.

    The result was scary.

    CODE IN THE BOOKING SUCCESS PAGE:

    {exp:weblog:entries}
    {embed="site/footer" foo="{google1}" moo="{entry_id}"}
    {/exp:weblog:entries}

    (im guessing that means something like ‘foreach weblog entry output another footer’)


    IN THE FOOTER:

    g1:{google1}
    g2:{google2}
    foo:{foo}
    moo:{moo}

    Resulted in a normal footer for most of the pages, but when i submitted a booking i got a lot of extra footers but unfortunately the variables still wasnt there.

    output in the first 100 or so extra footers:
    g1:{google1} g2:{google2} foo:{foo} moo:{moo}

  • #5 / Oct 28, 2008 5:35am

    ussher

    14 posts

    Oops I spoke too soon.  using the {embed:foo} the variables DID come out correctly! Thanks.

    Is there a way to limit that loop to only 1 footer?

  • #6 / Oct 28, 2008 6:02am

    ussher

    14 posts

    Hi Pushloop,

    I think ive got it this time.

    {embed="site/sidebar"}
    {embed="site/footer" foo="{google1}" moo="{entry_id}"}
    {/exp:query}

    Has done the trick! I have the footer and the output im wanting.  Thanks very much for your help.

  • #7 / Oct 29, 2008 9:18am

    pushloop

    422 posts

    Glad I could help 😊
    Please let me know how the final site turned out, as I’m very interested in how you integrated google e-commerce!

  • #8 / Oct 29, 2008 9:56pm

    ussher

    14 posts

    The google analytics code was already in place in the footer, so i just wanted to add the e-commerce tracking.

    Googles instructions:
    http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55528

    The site funnel path went like this:
    1. booking signup form
    2. booking success page

    So i needed to add the google e-commerce code to the success page, but AFTER the google analytics code.

    Since the booking page was an EE template page it would not have a footer (because this is handled by the template footer.)  So I needed to find a way to pass the variables from the success page to the footer page so that they could be included after the other code.

    The booking page was using a query to return the needed info from the database and get the variables i needed for the e-commerce

    {exp:query sql="SELECT (all the needed info)</code></pre>
    
    which returned the values in variables like this {entry_id}  
    
    So i got all the info that i could and passed it to the footer before closing the query
    <pre><code>{embed="site/footer"  orderid="{entry_id}" customers="{customers}" }
    {/exp:query}

    I would have liked more info, but due to the database structure i could only get the ID and the Customers.  Ideally you would get all the info that e-commerce is asking for.
    total transaction info:
    // booking number
    // Total Price
    // City
    booking transaction info
    // booking number
    // tour name
    // Price
    // number of people in the booking

    Then in the footer template, now it has the variables its just a question of entering them into the google code.

    [removed]
      var pageTracker = _gat._getTracker("xx-xxxxxxx-x");
      pageTracker._initData();
      pageTracker._trackPageview();
    
      pageTracker._addTrans(
        "{embed:orderid}",
        "",
        "1",
        "",
        "",
        "",
        "",
        ""
      );
    
      pageTracker._addItem(
        "{embed:orderid}",
        "",
        "",
        "",
        "1",
        "{embed:customers}"
      );

    but Check the google link above for the latest code structrue.  and fill the empty variables if you can. (those empty “”)

    —-edit—-
    it also needed:

    {if ({embed:orderid} >=1)} (the booking code){/if}

    so that the it would only be triggered if there was a booking id.  (saves sending new booking info with each pageview)

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases