Login to download the latest version of Mint and your favorite Pepper, purchase additional licenses, or post in the Forum. Don't have an account? Create one!

In Partnership with Media Temple

Mint Forum

Recording non URL values using the mint script initialisation

Hey guys,

I am considering writing a pepper that records ids of entries in my content management system.

The main issue I have is that the url of an entry may change so I was hoping to record the entry_id in a new mint table col.

Basically I was planning to add the following to the manifest:

  • entry_id
  • section_id

Can these details be recorded using the mint script call?

something like

Then use the $_GET super global in my mint pepper?

Any ideas would be appreciated.

Cheers

Shaun Inman
Mint/Pepper Developer
Posted on Jan 28, '08 at 10:17 am

Totally doable. Check the Pepper development links stuck at the top of this Forum.

Hey Shaun,

Thanks for your reply. I previously went the documentation and the only mention of $_GET variables was:

“The onRecord() event handler fires after the Mint JavaScript include has validated the hit and the Mint record method is called. It operates on existing $_GET values, values generated as a result of the Pepper’s optional JavaScript output or existing $_SERVER variables.”

I was not quite sure if this referred to the browser url: http://leevigraham.com/index.php?my_get_variable=true

or the mint initialisation call:

Can you clarify this and maybe post a quick example if needed?

Cheers

Shaun Inman
Mint/Pepper Developer
Posted on Jan 29, '08 at 09:55 am

Sure. Pepper PHP code isn’t run in page so if you want to detect those query variables you’ll need to do it in the JavaScript portion of your code.

The onJavaScript() Pepper method would output some JavaScript. That Javascript would access the pages query string and retrieve the values you want to track, those values would be returned by that JavaScript function url encoded name value pairs, eg. &my_get_variable=true&and_another=false

The onRecord() Pepper method would then do something with $_GET['my_get_variable'] et al.

The “existing $_GET values” the quote you mention refers to $_GET values created in this way by other Pepper. The example Pepper in the documentation describes how to do this. Download the source and check out the two methods mentioned above.

Hey Shaun,

Thanks for that… I guess I wasn’t as clear as I could have been.

Heres my situation….

I have a cms (expressionengine) that uses friendly urls for pages

eg: http://leevigraham.com/my_entry_url_title

Now my_entry_url_title can change at anytime but the entry id always stays the same.

I could record hits on those pages using the url but if the entry_url_title changes then mint would see this as another page, although it would be the same.

So I was hoping to pass the entry ID directly into mint like: http://mydomain.com/mint/?js&entry_id=1

However you have stated that the pepper php is not run in the page so I guess this is out of the question.

Another idea I had was to add the entry_id as a class on the body and use js to parse it out and save it back into mint like the window width pepper example.

Something like that… although ideally I would like to avoid the extra js calls even though they would be pretty small.

Shaun Inman
Mint/Pepper Developer
Posted on Jan 30, '08 at 10:12 am

You could use PHP to write an inline JavaScript tag before the Mint include that defines the entry_id value your Pepper needs as a simple JavaScript variable.

Ok that sounds like a plan….

So rather than using the onJavaScript() method to insert a custom script could I just do something like this inline on each page before the mint script is called:

<script type="text/javascript> if (!Mint.LG) { Mint.LG = new Object(); } Mint.LG.NewPepper = { onsave : function() { return '&entry_id=1; } }; </script>

or would I still need to use the onJavaScript() method to insert the pepper script.

So in my page I would have:

<script type="text/javascript> var lg_entry_id = 1; </script>

and my pepper included script would be:

if (!Mint.LG) { Mint.LG = new Object(); } Mint.LG.NewPepper = { onsave : function() { return '&entry_id=' + lg_entry_id; } };

Thanks for your patience and help on this one

Shaun Inman
Mint/Pepper Developer
Posted on Jan 31, '08 at 10:11 am

You would still need to use the onJavaScript() method because if you output your first example before the Mint JavaScript include then the Mint object doesn’t exist yet. If you output it after, your addition will have already missed the Mint.save() call.

Your lg_entry_id should be set before the Mint JavaScript include and your Pepper’s onJavaScript() method should define your Mint.LG object and children (which you already figured out).

Well that makes perfect sense :)

Thanks for your time.

You must be logged in to reply. Login above or create an account