OpenResty libriary to build a google_analytics webserver
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
resty
LICENSE
access.lua
readme.md

readme.md

Name

lua-resty-minami/google_analytics : Openresty library to build a google_analytics webserver

Table of Contents

Status

This library is considered passed testing and may change without notice.

Back to TOC

Description

This library requires a Openresty build, please take here as reference.

Back to TOC

Synopsis

# nginx.conf

# library folder 'resty' dir
lua_package_path "/path/to/conf/?.lua;;";



# website.conf
location / {
    ...
    
    access_by_lua_file  /path/to/conf/access.lua;
    
    if ($cookie_stats = "1") {
        rewrite ^/(.*)$ /$1 break;
        post_action @google_analytics;
    }
}

location @google_analytics {
    internal;
    
    resolver 8.8.8.8 ipv6=off;
    
    proxy_http_version          1.1;
    proxy_method                GET;
    proxy_set_header            User-Agent $http_user_agent;
    proxy_pass_request_headers  off;
    proxy_pass_request_body     off;
    # modify 'UA-111111111-1' to your google_analytics website number
    proxy_pass                  https://www.google-analytics.com/collect?v=1&t=pageview&tid=UA-111111111-1&cid=$cookie_cid&uip=$remote_addr&dh=$host&dp=$request_uri&dr=$http_referer&z=$msec;
}
-- access.lua

-- as to the following ".../"
-- you should modify it to absolute directory of root directory of your website
local request_filename = ".../" .. ngx.var.uri

Back to TOC

Author

Minami (Nanqinlang) (南琴浪) https://sometimesnaive.org

Back to TOC

Copyright and License

personal work, for non-profit, Copyright (C) 2018 All rights reserved.

This library's License: GPL v3.

Back to TOC

See Also

Back to TOC

According

https://sometimesnaive.org/article/76

Issue

this repo have a problem, which contributes to a further pharse between if and access_by_lua conception, if is earlier, which will results in a non-updated(incorrectly) cookie taken. so this repo doesn't work well.