Change Cookie TTL for AMP Tracker

Hey guys,
is it possible to change the cookie TTL for the Snowplow AMP tracker? Default time is 1 year but we would like to reduce this one.

There is an option to set the TTL in the cookie configuration of the Snowplow vendor in the AMP project (see Cookie Writer: Allow customization of expiration date · Issue #22422 · ampproject/amphtml (github.com)) but the Snowplow AMP tracker does not seem to implement this one. Could you give us here a hint how we can set this anyway somehow?

Thanks a lot! :slight_smile:

Best, Christoph

1 Like

At the moment this looks like it inherits the default value (1 year) - and it is possible to change this - by releasing a new AMP version of the Snowplow tracker.

This doesn’t look particularly difficult (add cookieLifetime as a new variable to the template) so someone on the Snowplow team might be able to pick this up (@Colm maybe?) - I’m not sure if AMP allow PRs outside of the vendor.

1 Like

thanks @mike for the fast reply. Let me know when we can support you with something (e.g. PR). You guys really help us with that, thanks a lot! :slight_smile:

Thanks @capchriscap for raising this.
We are happy to implement this change, as Mike said, the AMP tracker is different from the other trackers where we would be more than happy of receiving external PRs.
We’ll give a look next week. I’ll keep you in the loop!

2 Likes

Hi @Alex_Benini,
any news on the topic? Can we support you in any way here? :slight_smile:

Sorry for the late reply @capchriscap .
I produced something but it doesn’t work as I expected.
You can see the draft PR here.

I wrote a configuration like this one, with the idea that it would make the max age configurable:

"cookies": {
    "enabled": true,
    "cookieMaxAge": {
      "value": "$DEFAULT(${cookieMaxAge}, $CALC(86400, 365, multiply, true))"
    },
   ...
  },

…reading the implementation of the cookie-writer.js

const cookieMaxAgeNumber = Number(inputConfig['cookieMaxAge']);

I see that the value is directly converted to a number and the variables are not expanded which results in a NaN value.

I’m not sure how to set the cookieMaxAge making that custom for the user.

Any suggestion?
I’m not an AMP expert so I can probably miss something obvious.

Hi @Alex_Benini ,
thanks for testing this out! :slight_smile: Does it generally work with a hardcoded number?


Update: But I think you are right. We would need to firstly expand the configuration with

var cookieMaxAge = Number(this.urlReplacementService_.expandString(
 inputConfig['cookieMaxAge'],
  this.bindings_
))

Do you know how fast the pull request and release cycle of AMP is?

Hey @capchriscap, we revisited again this issue and seems it needs a bit more work to get the cookie-writer to expand values. (Even for allowing the client to add the cookieMaxAge, it would require the use of DEFAULT)

What we can do for now is push for this feature on the amphtml main repository issues and see if we can get this going. We are also keeping this in our backlog so as to revisit :slight_smile:

If you have any other solution in mind that can help with your use-cases, we would be happy to assist.

2 Likes

Hey Peter,

thanks a lot for the feedback and your effort! :slight_smile:

Could you also post the issue link you created at AMP within this ticket? Would be helpful to keep track. Thanks a lot! :slight_smile:

I did a quick search in Issues · ampproject/amphtml · GitHub and found these two issues (one open, one closed):

1 Like